Bug 271832 - od(1): fails to check -j value correctly
Summary: od(1): fails to check -j value correctly
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.2-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: Xin LI
URL: https://reviews.freebsd.org/D40446
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-05 00:44 UTC by Mohamed Akram
Modified: 2023-06-08 04:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohamed Akram 2023-06-05 00:44:08 UTC
To reproduce:

printf 1234 > file
od -j 5 file
echo $?

Expected output:

od: cannot skip past end of input
1

Actual output:

0000004
0


It seems to be misreading the file's size since larger values of -j (9+) work correctly.
Comment 1 Xin LI freebsd_committer freebsd_triage 2023-06-07 06:26:54 UTC
I think this should fix the issue.  It appears that the bug existed for a little bit more than 21 years.
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-06-08 01:06:35 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1232c7884d4a9bc69d4dd71cd293f92bb1ae6197

commit 1232c7884d4a9bc69d4dd71cd293f92bb1ae6197
Author:     Xin LI <delphij@FreeBSD.org>
AuthorDate: 2023-06-08 01:06:07 +0000
Commit:     Xin LI <delphij@FreeBSD.org>
CommitDate: 2023-06-08 01:06:07 +0000

    od(1): Fix skip value handling

    POSIX defines -j as the number of bytes that od(1) should skip over the
    concatenated input files. The existing code tries to implement this behavior
    by checking if the current address was smaller than the skip value. However,
    this is not correct, because we adjust both the skip value and the address
    at the same time when we do fseeko (when file is seekable) or getchar (when
    file is not seekable).

    This commit fixes the problem by expecting the skip value to be zero upon
    return of next(). If the condition is not satisfied, a diagnostic message
    will be issued.

    Reported-by:    Mohamed Akram <mohd.akram@outlook.com>
    Reviewed-by:    emaste
    PR:             271832
    MFC-after:      2 weeks
    Differential Revision: https://reviews.freebsd.org/D40446

 usr.bin/hexdump/display.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)