Tar filename with exactly 100 characters gets cut #322

Closed
opened 2026-01-29 22:10:07 +00:00 by claunia · 2 comments
Owner

Originally created by @majoreffort on GitHub (Jul 23, 2018).

Filenames with exactly 100 characters loose their last character while writing the header (TarHeader#Write).

I wrote a simple test to verify this issue: See ec044e6f42

I also digged into the code and found the method WriteStringBytes actually writes a maximum of length-1 bytes:

for (i = 0; i < length - 1 && i < name.Length; ++i)
{
    buffer[offset + i] = (byte)name[i];
}

Is this intended and/or tar only supports 99 character entries?
If I replace length - 1 with only length the tar tests work fine.

Originally created by @majoreffort on GitHub (Jul 23, 2018). Filenames with exactly 100 characters loose their last character while writing the header (TarHeader#Write). I wrote a simple test to verify this issue: See ec044e6f42a60159e36b95689960ba55e4fbcb4f I also digged into the code and found the method `WriteStringBytes` actually writes a maximum of length-1 bytes: ```csharp for (i = 0; i < length - 1 && i < name.Length; ++i) { buffer[offset + i] = (byte)name[i]; } ``` Is this intended and/or tar only supports 99 character entries? If I replace `length - 1` with only `length` the tar tests work fine.
Author
Owner

@adamhathcock commented on GitHub (Jul 23, 2018):

Mind submitting the test and a fix as a pull request? Thanks!

@adamhathcock commented on GitHub (Jul 23, 2018): Mind submitting the test and a fix as a pull request? Thanks!
Author
Owner

@majoreffort commented on GitHub (Jul 23, 2018):

Sure, added PR #408.

@majoreffort commented on GitHub (Jul 23, 2018): Sure, added PR #408.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#322