Hi,

I was playing around with dd today and noticed something strange. The
specification[1] states:

> If the swab conversion is specified, each pair of input data bytes
> shall be swapped. If there is an odd number of bytes in the input
> block, the last byte in the input record shall not be swapped.

The OpenBSD man page similarly says:

> Swap every pair of input bytes. If an input buffer has an odd number
> of bytes, the last byte will be ignored during swapping.

I understand this to mean that if ibs is set to an odd value, every
ibs'th byte in the output file keeps the value from the input file.
Similarly with partial blocks of odd length.

I created a file with the following contents (59 bytes, including the
newline at the end):
> Hi! I have 3 words for you. Just kidding, there were more.

And ran dd on it like this:
> $ dd if=atextfile.txt of=swap.txt ibs=11 conv=swab
> 5+1 records in
> 0+1 records out
> 4 odd length swab blocks
> 59 bytes transferred in 0.000 secs (1053571 bytes/sec)

I would have expected dd to report 5 odd length blocks here. When view-
ing the result in hexdump, I found the byte at offset 0xA to be the
same as in the original file, but at 0x15, 0x20, 0x2B and 0x36, they
are replaced by the value 0.

Checking other implementations, I found FreeBSD's dd to give the exact
result I expected (5 odd length swab blocks and the original bytes at
the aforementioned offsets) and GNU not even trying to adhere to any
sensible interpretation of the specification (swapping between border-
ing blocks and all over the place).

English is not my native language, so maybe there is ambiguity in the
specification, which I failed to pick up. But I thought it might be a
bug, so I decided to report my observation.

Have a good time,
Martin

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dd.html

Reply via email to