GNU bug report logs - #24874
dd: misleading parsing of hex numbers

Previous Next

Package: coreutils;

Reported by: Stephan Bauroth <der_steffi <at> gmx.de>

Date: Fri, 4 Nov 2016 15:40:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24874 in the body.
You can then email your comments to 24874 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#24874; Package coreutils. (Fri, 04 Nov 2016 15:40:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stephan Bauroth <der_steffi <at> gmx.de>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 04 Nov 2016 15:40:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephan Bauroth <der_steffi <at> gmx.de>
To: bug-coreutils <at> gnu.org
Subject: dd: misleading parsing of hex numbers
Date: Fri, 4 Nov 2016 12:19:40 +0100
Dear coreutils team :)

I encountered a buglike behaviour of dd when handling skip and count 
parameters that are encoded in hex and thus prefixed with 0x.

dd is not able to parse them, which is OK but would be great if it would 
be, but, worse, reads 0xf00 as 0. It does that silently. While an 
enduser will immediately notice this on count, since nothing is copied, 
behaviour for skip looks ok. (In fact, I noticed this only because I 
hexdumped the result after hours of debugging)

While it's OK that dd can't parse these numbers, maybe there should be a 
warning that 0x was found and interpreted as 0. Since a char like 'x' is 
invalid within a number that by definition has to be decimal, a warning 
should be fairly easy to implement.

Of course, the ability to parse hex numbers in these parameters would be 
awesome :)

regards and thanks for your continuing work,
Stephan Bauroth




Information forwarded to bug-coreutils <at> gnu.org:
bug#24874; Package coreutils. (Fri, 04 Nov 2016 16:21:02 GMT) Full text and rfc822 format available.

Message #8 received at 24874 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephan Bauroth <der_steffi <at> gmx.de>, 24874 <at> debbugs.gnu.org
Subject: Re: bug#24874: dd: misleading parsing of hex numbers
Date: Fri, 4 Nov 2016 16:20:50 +0000
On 04/11/16 11:19, Stephan Bauroth wrote:
> Dear coreutils team :)
> 
> I encountered a buglike behaviour of dd when handling skip and count 
> parameters that are encoded in hex and thus prefixed with 0x.
> 
> dd is not able to parse them, which is OK but would be great if it would 
> be, but, worse, reads 0xf00 as 0. It does that silently. While an 
> enduser will immediately notice this on count, since nothing is copied, 
> behaviour for skip looks ok. (In fact, I noticed this only because I 
> hexdumped the result after hours of debugging)
> 
> While it's OK that dd can't parse these numbers, maybe there should be a 
> warning that 0x was found and interpreted as 0. Since a char like 'x' is 
> invalid within a number that by definition has to be decimal, a warning 
> should be fairly easy to implement.
> 
> Of course, the ability to parse hex numbers in these parameters would be 
> awesome :)
> 
> regards and thanks for your continuing work,
> Stephan Bauroth

Ouch. That's a real gotcha.
Note hex digits after the 0x are diagnosed, but not decimal digits:

  $ dd skip=0x100 seek=0xf00
  dd: invalid number: ‘0xf00’

Disallowing 0x... could definitely break backwards compat though.
Consider `for rec in 0 1 2; do dd skip=${rec}x1024...`

I suppose we could output a warning to suggest using
  $(($rec * $size)) or 0${rec}x${size}
if that really is the intention?

Given the warning workaround would be suggested in the message,
and that it's a relatively rare usage, a warning is probably appropriate here.
We already warn in dd for various usage.

I'll fix that for the coming release.

thanks,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#24874; Package coreutils. (Fri, 04 Nov 2016 17:04:01 GMT) Full text and rfc822 format available.

Message #11 received at 24874 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Stephan Bauroth <der_steffi <at> gmx.de>, 24874 <at> debbugs.gnu.org
Subject: Re: bug#24874: dd: misleading parsing of hex numbers
Date: Fri, 4 Nov 2016 17:03:29 +0000
[Message part 1 (text/plain, inline)]
On 04/11/16 16:20, Pádraig Brady wrote:
> On 04/11/16 11:19, Stephan Bauroth wrote:
>> Dear coreutils team :)
>>
>> I encountered a buglike behaviour of dd when handling skip and count 
>> parameters that are encoded in hex and thus prefixed with 0x.
>>
>> dd is not able to parse them, which is OK but would be great if it would 
>> be, but, worse, reads 0xf00 as 0. It does that silently. While an 
>> enduser will immediately notice this on count, since nothing is copied, 
>> behaviour for skip looks ok. (In fact, I noticed this only because I 
>> hexdumped the result after hours of debugging)
>>
>> While it's OK that dd can't parse these numbers, maybe there should be a 
>> warning that 0x was found and interpreted as 0. Since a char like 'x' is 
>> invalid within a number that by definition has to be decimal, a warning 
>> should be fairly easy to implement.
>>
>> Of course, the ability to parse hex numbers in these parameters would be 
>> awesome :)
>>
>> regards and thanks for your continuing work,
>> Stephan Bauroth
> 
> Ouch. That's a real gotcha.
> Note hex digits after the 0x are diagnosed, but not decimal digits:
> 
>   $ dd skip=0x100 seek=0xf00
>   dd: invalid number: ‘0xf00’
> 
> Disallowing 0x... could definitely break backwards compat though.
> Consider `for rec in 0 1 2; do dd skip=${rec}x1024...`
> 
> I suppose we could output a warning to suggest using
>   $(($rec * $size)) or 0${rec}x${size}
> if that really is the intention?
> 
> Given the warning workaround would be suggested in the message,
> and that it's a relatively rare usage, a warning is probably appropriate here.
> We already warn in dd for various usage.
> 
> I'll fix that for the coming release.

Patch attached.

[dd-0x-warn.patch (text/x-patch, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#24874; Package coreutils. (Fri, 04 Nov 2016 18:20:02 GMT) Full text and rfc822 format available.

Message #14 received at 24874 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Pádraig Brady <P <at> draigbrady.com>
Cc: Stephan Bauroth <der_steffi <at> gmx.de>, 24874 <at> debbugs.gnu.org
Subject: Re: bug#24874: dd: misleading parsing of hex numbers
Date: Fri, 4 Nov 2016 13:18:55 -0500
On Fri, Nov 4, 2016 at 12:03 PM, Pádraig Brady <P <at> draigbrady.com> wrote:
> On 04/11/16 16:20, Pádraig Brady wrote:
>> On 04/11/16 11:19, Stephan Bauroth wrote:
>>> Dear coreutils team :)
>>>
>>> I encountered a buglike behaviour of dd when handling skip and count
>>> parameters that are encoded in hex and thus prefixed with 0x.
>>>
>>> dd is not able to parse them, which is OK but would be great if it would
>>> be, but, worse, reads 0xf00 as 0. It does that silently. While an
>>> enduser will immediately notice this on count, since nothing is copied,
>>> behaviour for skip looks ok. (In fact, I noticed this only because I
>>> hexdumped the result after hours of debugging)
>>>
>>> While it's OK that dd can't parse these numbers, maybe there should be a
>>> warning that 0x was found and interpreted as 0. Since a char like 'x' is
>>> invalid within a number that by definition has to be decimal, a warning
>>> should be fairly easy to implement.
>>>
>>> Of course, the ability to parse hex numbers in these parameters would be
>>> awesome :)
>>>
>>> regards and thanks for your continuing work,
>>> Stephan Bauroth
>>
>> Ouch. That's a real gotcha.
>> Note hex digits after the 0x are diagnosed, but not decimal digits:
>>
>>   $ dd skip=0x100 seek=0xf00
>>   dd: invalid number: ‘0xf00’
>>
>> Disallowing 0x... could definitely break backwards compat though.
>> Consider `for rec in 0 1 2; do dd skip=${rec}x1024...`
>>
>> I suppose we could output a warning to suggest using
>>   $(($rec * $size)) or 0${rec}x${size}
>> if that really is the intention?
>>
>> Given the warning workaround would be suggested in the message,
>> and that it's a relatively rare usage, a warning is probably appropriate here.
>> We already warn in dd for various usage.
>>
>> I'll fix that for the coming release.
>
> Patch attached.

Ouch, confusing indeed. I like your solution. One nit:

- dd if=/dev/null count=0x1 seek=0x1 skip=0x1 status=none 2>err
+ dd if=/dev/null count=0x1 seek=0x1 skip=0x1 status=none 2>err || fail=1




bug closed, send any further explanations to 24874 <at> debbugs.gnu.org and Stephan Bauroth <der_steffi <at> gmx.de> Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Sat, 05 Nov 2016 00:51:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 03 Dec 2016 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 258 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.