Skip to content

Fix: Correctly parse xxd odd byte hexdumps #2058

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ThomasNotTom
Copy link

Description

xxd produces hex bytes in pairs. However when an odd number of bytes are present, the final byte is not parsed and is therefore not included in the output.

This fixes issue #2033

Fix

The fix involves altering the RegEx to, in the final segment of bytes, include either 2 or 4 character segments (IE 1 or 2 bytes).

@ThomasNotTom
Copy link
Author

Seems to work for xxd hexdumps but no longer toHexdump dumps, will look into now

@ThomasNotTom
Copy link
Author

ThomasNotTom commented Jun 6, 2025

The inner of the 3 byte segment RegEx checks (which matches 2 byte segments IE 6162 6364), was adjusted to match 2 byte segments ending in a single byte (IE 6162 63). However due to the structure of the RegEx the first two bytes could be matched 0 or more times. This meant that single byte segments (IE 61) were being matched and returned early (as the adjusted version only matched a single byte, only appearing once).

The fix was to adjust the 2 byte segments to match 1 or more times (not 0 or more) and then have an optional match at the end for a single byte. For RegExs that fail the '2 byte segments appearing 1 or more times' will be handled by the other 2 cases in the RegEx that handle single bytes, spaced apart (IE 61 62 63).

With these adjustments the RegEx handles 2 byte segments ending with a single byte, without interfering with the other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant