* NEWS: Mention the bug fix.
* src/od.c (dump): Don't break the look on read error.
* tests/od/od.pl: Add a test case.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-DYUIRPOE.
Link: https://github.com/coreutils/coreutils/issues/402
---
 NEWS           | 5 +++++
 src/od.c       | 5 ++---
 tests/od/od.pl | 8 ++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 02bb0d05c..047908a0d 100644
--- a/NEWS
+++ b/NEWS
@@ -100,6 +100,11 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   od now exits gracefully when offsets overflow integer limits.
   [This bug was present in "the beginning".]
 
+  od now continues to process inputs upon read error.
+  Previously it would stop after the block being read, and then output
+  a block of uninitialized or previously output data.
+  [bug introduced in coreutils-9.4]
+
   'pr' no longer reads past its internal buffer and crashes when it reads more
   than INT_MAX bytes of column data for a single page.
   [This bug was present in "the beginning".]
diff --git a/src/od.c b/src/od.c
index 25ac0cd54..ed9531547 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1537,7 +1537,7 @@ dump (void)
 
   intmax_t current_offset = n_bytes_to_skip;
 
-  do
+  while (true)
     {
       intmax_t needed_bound
         = end_offset < 0 ? INTMAX_MAX : end_offset - current_offset;
@@ -1554,11 +1554,10 @@ dump (void)
       write_block (current_offset, n_bytes_read,
                    block[!idx], block[idx]);
       if (ferror (stdout))
-        ok = false;
+        write_error ();
       current_offset = offset_add (current_offset, n_bytes_read);
       idx = !idx;
     }
-  while (ok);
 
   if (n_bytes_read > 0)
     {
diff --git a/tests/od/od.pl b/tests/od/od.pl
index 701950ac8..a91925b7d 100755
--- a/tests/od/od.pl
+++ b/tests/od/od.pl
@@ -115,6 +115,14 @@ my @Tests =
       {OUT=>"0000001 hello\n0000007 world\n"}],
      ['S-Ao', '-Ao -S3', {IN=>"\001hello\000world\000ab\000"},
       {OUT=>"0000001 hello\n0000007 world\n"}],
+
+     # Ensure that all remaining input is output following an input error.
+     # From coreutils-9.4 through coreutils-9.12, od would stop after the
+     # block being read, and then output an uninitialized or stale block.
+     ['read-err-1', '-An -c -w4', {IN=>{g=>'a'}}, 'missing',
+      {IN=>{h=>'bcdefghij'}}, {EXIT=>1},
+      {OUT=>"   a   b   c   d\n   e   f   g   h\n   i   j\n"},
+      {ERR=>"$prog: missing: $limits->{ENOENT}\n"}],
     );
 
 push @Tests,
-- 
2.56.0


Reply via email to