From: Paul Eggert Date: Mon, 30 Jun 2025 05:31:01 +0000 (-0700) Subject: od: add test cases for recent fix X-Git-Tag: v9.8~260 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c5f069a4c8f33a0177acd021df2f4cad6860024;p=thirdparty%2Fcoreutils.git od: add test cases for recent fix * tests/od/od.pl: New tests for the offset issues --- diff --git a/NEWS b/NEWS index a85840dda3..87ba2659cf 100644 --- a/NEWS +++ b/NEWS @@ -27,6 +27,9 @@ GNU coreutils NEWS -*- outline -*- od '+N.' (where N is a decimal number) works again as per POSIX. [bug introduced in textutils-2.0] + 'od /dev/null ++0' no longer mistakenly treats the ++0 as an offset. + [This bug was present in "the beginning".] + sort with key character offsets of SIZE_MAX, could induce a read of 1 byte before an allocated heap buffer. For example: 'sort +0.18446744073709551615R input' on 64 bit systems. diff --git a/tests/od/od.pl b/tests/od/od.pl index 9688607c6e..e4e328ad68 100755 --- a/tests/od/od.pl +++ b/tests/od/od.pl @@ -64,6 +64,24 @@ my @Tests = ['trad-dot1', '+1.', {IN_PIPE=>'a'}, {OUT=>"0000001\n"}], ['trad-dot512', '+1.b', {IN_PIPE => 'a' x 512}, {OUT=>"0001000\n"}], + # Invalid traditional offsets should be treated as file names. + ['invalid-off-1', '++0', {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"$prog: ++0: No such file or directory\n"}], + ['invalid-off-2', '+-0', {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"$prog: +-0: No such file or directory\n"}], + ['invalid-off-3', '"+ 0"', {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"$prog: '+ 0': No such file or directory\n"}], + ['invalid-off-4', '-- -0', {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"$prog: -0: No such file or directory\n"}], + + # Overflowing traditional offsets should be diagnosed. + ['overflow-off-1', '-', '7' x 255, {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"od: ".('7' x 255).": Numerical result out of range\n"}], + ['overflow-off-2', '-', ('9' x 254).'.', {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"od: ".('9' x 254).".: Numerical result out of range\n"}], + ['overflow-off-3', '-', '0x'.('f' x 253), {IN_PIPE=>""}, {EXIT=>1}, + {ERR=>"od: 0x".('f' x 253).": Numerical result out of range\n"}], + # Ensure that a large width does not cause trouble. # From coreutils-7.0 through coreutils-8.21, these would print # approximately 128KiB of padding.