Re: Bug in hexdump when offset == file length

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 26, 2009 at 10:19:37PM +0800, Américo Wang wrote:
> On Thu, Nov 26, 2009 at 03:42:21AM -0500, Mike Smith wrote:
> >> It's not a bug, it is an undocumented feature, IMO.
> >> When you give an offset which is larger than the file size, it will wrap
> >> back.
> >
> >Then it's still buggy.
> >[mike@laptop ~]$ dd if=/dev/urandom of=testfile bs=1 count=42
> >42+0 records in
> >42+0 records out
> >42 bytes (42 B) copied, 0.000216179 s, 194 kB/s
> >[mike@laptop ~]$ hexdump -Cv testfile -s 42
> >0000002a  bb b0 ba 50 fe 70 f8 d9  f7 96 36 49 e9 74 c7 bd  |...P.p....6I.t..|
> >0000003a  82 cb 19 64 a6 30 53 29  d2 fa 08 e3 f4 26 7f de  |...d.0S).....&..|
> >0000004a  bb 2c f2 df 7c a7 8c 6e  66 01                    |.,..|..nf.|
> >00000054
> >[mike@laptop ~]$ hexdump -Cv testfile -s 43
> >0000002a
> 
> Good spot!
> 
> I think I got where the bug is, it's an off-by-one problem...

 Yes.

> When offset equals to the size of the file, do seek to the end
> and read nothing.

 More precisely: it does not call seek() in such situation, the file is 
 ignored at all in the next() function.

 BTW, quotation from POSIX (it uses a different name ("od") and
 option -j):

 −j skip Jump over skip bytes from the beginning of the input. The od
         utility shall read or seek past the first skip bytes in the
         concatenated input files. If the combined input is not at least skip
         bytes long, the od utility shall write a diagnostic message to
         standard error and exit with a non-zero exit status.

 Our version does not print any diagnostic message.

> This is an off-by-one problem.
> 
> Signed-off-by: WANG Cong <xiyou.wangcong@xxxxxxxxx>

 Applied, thanks.

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux