fix: parse uid/gid as octal numbers per POSIX tar spec#62
Conversation
Fixes unjs#40 The tar specification stores uid and gid as octal ASCII strings. The code was using Number.parseInt() which defaults to base 10, causing values like 0o1751 (decimal 1001) to be parsed as 1751. Use _readNumber() which correctly parses with radix 8, matching the behavior already used for size and mtime fields.
📝 WalkthroughWalkthroughThe TAR file parser's handling of Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/parse.ts (1)
57-60: Please add a regression test for octaluid/giddecoding.This bug is easy to reintroduce; a fixture/assertion for values like
01751(expected decimal1001) would lock the behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/parse.ts` around lines 57 - 60, Add a regression test that constructs a tar header buffer (or uses an existing fixture) with octal UID/GID strings like "01751" and asserts that the parser decodes them to decimal 1001; specifically exercise the code paths that call _readNumber so the uid and gid fields produced by the parser (the uid and gid values derived from _readNumber) are compared against expected numeric values. Ensure the test covers both uid and gid decoding, includes leading/trailing NULs or spaces typical of tar headers, and fails if _readNumber returns the octal string instead of the decimal numeric value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/parse.ts`:
- Around line 57-60: Add a regression test that constructs a tar header buffer
(or uses an existing fixture) with octal UID/GID strings like "01751" and
asserts that the parser decodes them to decimal 1001; specifically exercise the
code paths that call _readNumber so the uid and gid fields produced by the
parser (the uid and gid values derived from _readNumber) are compared against
expected numeric values. Ensure the test covers both uid and gid decoding,
includes leading/trailing NULs or spaces typical of tar headers, and fails if
_readNumber returns the octal string instead of the decimal numeric value.
Fixes #40
Problem
The POSIX tar specification stores
uidandgidfields as octal ASCII strings. The code was usingNumber.parseInt()which defaults to base 10, causing values like01751(decimal 1001) to be parsed as 1751.Fix
Replaced
Number.parseInt(_readString(...))with_readNumber(...)for both uid and gid fields._readNumberalready correctly parses with radix 8, matching the behavior used forsizeandmtimefields.Summary by CodeRabbit