call delete(outfile)
endfunc
+func Test_xxd_reverse_long_input()
+ " triggered UB in huntype()
+ let input = 'Xxd_reverse_input'
+ call writefile([repeat('1', 515)], input, 'D')
+
+ " When this triggers undefined behaviour, there will be a warning output
+ " from the system() command
+ let out = system(s:xxd_cmd . ' -r ' . input)
+ call assert_equal('', out)
+ let out = system(s:xxd_cmd . ' -b -r ' . input)
+ call assert_equal('', out)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
* 25.03.2026 Fix color output issues
* 26.04.2026 Use unsigned long for printing offsets
* 31.05.2026 Colorize binary output
+ * 15.06.2026 Fix UB in huntype()
*
* (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com)
*
# endif
#endif
-char version[] = "xxd 2026-05-31 by Juergen Weigert et al.";
+char version[] = "xxd 2026-06-16 by Juergen Weigert et al.";
#ifdef WIN32
char osver[] = " (Win32)";
#else
bt = parse_bin_digit(c);
if (bt != -1)
{
- b = ((b << 1) | bt);
+ /* shift via unsigned to avoid signed overflow on bad input */
+ b = (int)(((unsigned)b << 1) | (unsigned)bt);
++bcnt;
}
}
p = 0;
continue;
}
- want_off = (want_off << 4) | n1;
+ want_off = (long)(((unsigned long)want_off << 4) | (unsigned)n1);
}
else /* HEX_BITS */
{
bcnt = 0;
continue;
}
- want_off = (want_off << 4) | n1;
+ want_off = (long)(((unsigned long)want_off << 4) | (unsigned)n1);
}
continue;
}
{
strcpy(z, l);
if (colors)
- {
memcpy(z_colors, colors, strlen(z));
- }
}
if (nz || !zero_seen++)