* src/od.c (dump_strings): Fix the loop termination test.
* tests/od/od-N.sh: Add a test case.
* NEWS: Mention the bug fix.
Discovered by Anthropic's OSS Scanner, as bug ANT-2026-7SQE0QSO.
---
NEWS | 4 ++++
src/od.c | 2 +-
tests/od/od-N.sh | 11 +++++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 5a239b1fa..925718fa6 100644
--- a/NEWS
+++ b/NEWS
@@ -259,6 +259,10 @@ GNU coreutils NEWS -*-
outline -*-
a block of uninitialized or previously output data.
[bug introduced in coreutils-9.4]
+ 'od --strings=0' with '-N' no longer loops forever, outputting empty
+ strings, once the -N limit is reached.
+ [bug introduced in coreutils-9.8]
+
'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 ec48b182b..0120fd537 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1604,7 +1604,7 @@ dump_strings (void)
int c = 1; /* Init to 1 so can distinguish if NUL read. */
if (0 <= end_offset
- && (end_offset < string_min || end_offset - string_min < address))
+ && (end_offset <= address || end_offset - address < string_min))
break;
/* Store consecutive printable characters to BUF. */
diff --git a/tests/od/od-N.sh b/tests/od/od-N.sh
index db36ba3de..44b1e2665 100755
--- a/tests/od/od-N.sh
+++ b/tests/od/od-N.sh
@@ -54,6 +54,17 @@ printf '\001%10s\000%10s\000' | od -S10 > out || fail=1
printf '%07o %10s\n' 1 '' 12 '' > exp || framework_failure_
compare exp out || fail=1
+# coreutils 9.8 to 9.12 would loop forever outputting empty strings
+# once the -N limit was reached. Use head to bound the output in that case.
+printf 'ab\000cd\000ef' | od -N6 -S0 | head -n9 > out &&
+printf '%07o %s\n' 0 ab 3 cd > exp || framework_failure_
+compare exp out || fail=1
+printf 'abcdefgh' | od -N4 -S0 | head -n9 > out &&
+printf '%07o %s\n' 0 abcd > exp || framework_failure_
+compare exp out || fail=1
+od -N0 -S0 < /dev/null | head -n9 > out || framework_failure_
+compare /dev/null out || fail=1
+
# Ensure T, P and E suffixes work after a 0 or 0x prefix
od -An -c in > exp || framework_failure_
for n in 01T 01P 01E 01TB 01PB 01EB 0x1T 0x1P; do
--
2.56.0