Bug 13246 - Incorrect end offset reported by 'hexdump' and 'od'
Summary: Incorrect end offset reported by 'hexdump' and 'od'
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: PC All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-08 07:32 UTC by mrother
Modified: 2020-11-17 16:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Fix for a bug in 'libbb/dump.c' (909 bytes, patch)
2020-10-08 07:32 UTC, mrother
Details
Config used for testing (6.87 KB, application/gzip)
2020-10-08 07:33 UTC, mrother
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mrother 2020-10-08 07:32:06 UTC
Created attachment 8586 [details]
Fix for a bug in 'libbb/dump.c'

When not using the '-v' option a single asterisk in the output of 'hexdump' and 'od' means that the output line(s) have the same contents (except for the input offsets) as the immediately preceding line.

The last output line should be the value of the end offset, which should be identical to the length of the input.

Currently (and as far as I can tell maybe since forever) the applets in question are reporting an incorrect end offset, IF the last "line" of the input has the same contents as the immediately preceding one, AND the input length is not a multiple of the line length.

Here is a simple example:
OK (reported end offset of 0x20 equals 32 as expected):
  head -c 32 /dev/zero | busybox hexdump -C
  00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  *
  00000020
WRONG (reported end offset of 0x20 equals 32, but 0x28 equals 40 was expected):
  head -c 40 /dev/zero | busybox hexdump -C
  00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
  *
  00000020

I originally stumbled over this bug on Windows, but have done my analysis on a Linux system.

I've come to the conclusion that in 'get()' of 'libbb/dump.c' the zero-padding, and address adjustment needs to be brought forward, so that it occurs prior to the test of identical input contents.

I'm attaching a patch, that has helped to resolve the issue for me.
Comment 1 mrother 2020-10-08 07:33:19 UTC
Created attachment 8591 [details]
Config used for testing
Comment 2 Denys Vlasenko 2020-11-17 16:41:11 UTC
Fixed in git.