Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

od: zero-fill input to required byte length #154

Merged
merged 1 commit into from Apr 29, 2023

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Apr 14, 2023

  • I noticed that when the number of input bytes is odd, the output of od -x is incorrect
  • This was because unpack('S', $data) returns nothing if $data is 1 byte
  • Standard od zero-fills the 16 bit number
  • The do-remainder-bytes logic is incorrect (tangled web of pack, unpack and substr)
  • float() and long() require input to be zero-filled 32-bits
  • udecimal(), decimal(), octal2() and hex() require input to be zero-filled 16-bits
  • Patch tested on amd64 against GNU od

Original output which uncovered this:
$ perl hexdump test
00000000 c6 f3 |..|
$ od -j 1 -x test # gnu od
0000001 00f3
0000002
$ perl od -j 1 -x test
00000001 0001
00000002

Also without -j:
$ xxd in2
00000000: d8ab 7a ..z
$ perl od -x in2
00000000 abd8 0000
00000003

* I noticed that when the number of input bytes is odd, the output of od -x is incorrect
* This was because unpack('S', $data) returns nothing if $data is 1 byte
* Standard od zero-fills the 16 bit number
* The do-remainder-bytes logic is incorrect (tangled web of pack, unpack and substr)
* float() and long() require input to be zero-filled 32-bits
* udecimal(), decimal(), octal2() and hex() require input to be zero-filled 16-bits
* Patch tested on amd64 against GNU od

Original output which uncovered this:
$ perl hexdump test
00000000  c6 f3                                             |..|
$ od -j 1 -x test # gnu od
0000001 00f3
0000002
$ perl od -j 1 -x test
00000001 0001
00000002

Also without -j:
$ xxd in2 
00000000: d8ab 7a                                  ..z
$ perl od -x in2
00000000 abd8 0000
00000003
@briandfoy briandfoy self-assigned this Apr 14, 2023
@briandfoy briandfoy added Type: bug an existing feature does not work Priority: low get to this whenever labels Apr 14, 2023
@briandfoy
Copy link
Owner

I see this, but I'm about to leave for a couple weeks so I'll deal with it when I get back.

@briandfoy briandfoy merged commit 93e87d5 into briandfoy:master Apr 29, 2023
1 check passed
@briandfoy briandfoy removed the Priority: low get to this whenever label Apr 29, 2023
@briandfoy briandfoy added Status: accepted The fix is accepted Program: od The od program Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: od The od program Status: released there is a new release with this fix Type: bug an existing feature does not work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants