Incorrect encoding when filename had more than 100 characters #100

Open
opened 2026-01-29 22:06:34 +00:00 by claunia · 8 comments
Owner

Originally created by @alexandrejh on GitHub (Jul 4, 2016).

When the filename had more than 100 characters and diacritics the folder name is created with wrong encode and the filename is cutted (e.g. if the name is myword.docx in tar.gz file the name is myword.do)

Originally created by @alexandrejh on GitHub (Jul 4, 2016). When the filename had more than 100 characters and diacritics the folder name is created with wrong encode and the filename is cutted (e.g. if the name is myword.docx in tar.gz file the name is myword.do)
Author
Owner

@adamhathcock commented on GitHub (Jul 4, 2016):

Tar has a size limitation on names. I guess an exception should be thrown instead of truncating. Thoughts?

Any chance of a pull request fix?

@adamhathcock commented on GitHub (Jul 4, 2016): Tar has a size limitation on names. I guess an exception should be thrown instead of truncating. Thoughts? Any chance of a pull request fix?
Author
Owner

@alexandrejh commented on GitHub (Jul 4, 2016):

At this moment i used a work around in my code (remove diacritics from the path) but this is not good because this name is typed by user.
In TarHeader has the code above that works differently when the filename has more than 100 characters.

//Encoding.UTF8.GetBytes("magic").CopyTo(buffer, 257);
if (Name.Length > 100)
{
// Set mock filename and filetype to indicate the next block is the actual name of the file
WriteStringBytes("././@LongLink", buffer, 0, 100);
buffer[156] = (byte) EntryType.LongName;
WriteOctalBytes(Name.Length + 1, buffer, 124, 12);
}
else
{
WriteStringBytes(Name, buffer, 0, 100);
WriteOctalBytes(Size, buffer, 124, 12);
var time = (long) (LastModifiedTime.ToUniversalTime() - Epoch).TotalSeconds;
WriteOctalBytes(time, buffer, 136, 12);
buffer[156] = (byte) EntryType;

            if (Size >= 0x1FFFFFFFF)
            {
                byte[] bytes = DataConverter.BigEndian.GetBytes(Size);
                var bytes12 = new byte[12];
                bytes.CopyTo(bytes12, 12 - bytes.Length);
                bytes12[0] |= 0x80;
                bytes12.CopyTo(buffer, 124);
            }
        }
@alexandrejh commented on GitHub (Jul 4, 2016): At this moment i used a work around in my code (remove diacritics from the path) but this is not good because this name is typed by user. In TarHeader has the code above that works differently when the filename has more than 100 characters. > //Encoding.UTF8.GetBytes("magic").CopyTo(buffer, 257); > if (Name.Length > 100) > { > // Set mock filename and filetype to indicate the next block is the actual name of the file > WriteStringBytes("././@LongLink", buffer, 0, 100); > buffer[156] = (byte) EntryType.LongName; > WriteOctalBytes(Name.Length + 1, buffer, 124, 12); > } > else > { > WriteStringBytes(Name, buffer, 0, 100); > WriteOctalBytes(Size, buffer, 124, 12); > var time = (long) (LastModifiedTime.ToUniversalTime() - Epoch).TotalSeconds; > WriteOctalBytes(time, buffer, 136, 12); > buffer[156] = (byte) EntryType; ``` if (Size >= 0x1FFFFFFFF) { byte[] bytes = DataConverter.BigEndian.GetBytes(Size); var bytes12 = new byte[12]; bytes.CopyTo(bytes12, 12 - bytes.Length); bytes12[0] |= 0x80; bytes12.CopyTo(buffer, 124); } } ```
Author
Owner

@adamhathcock commented on GitHub (Jul 4, 2016):

Sounds like you have a good handle on the issue. I'm not a tar expert but it might be cause tar only expects to deal with ASCII characters? I don't really know.

Could you make a PR that could fix this for everyone?

@adamhathcock commented on GitHub (Jul 4, 2016): Sounds like you have a good handle on the issue. I'm not a tar expert but it might be cause tar only expects to deal with ASCII characters? I don't really know. Could you make a PR that could fix this for everyone?
Author
Owner

@alexandrejh commented on GitHub (Jul 4, 2016):

yes, i can do the PR, but remove all folder name diacritics is interesting? if yes i can do.

@alexandrejh commented on GitHub (Jul 4, 2016): yes, i can do the PR, but remove all folder name diacritics is interesting? if yes i can do.
Author
Owner

@alexandrejh commented on GitHub (Jul 5, 2016):

when i try to open the project in my VS 2015 i got this error

D:\VisualStudio\SharpCompress\sharpcompress\src\SharpCompress\SharpCompress.xproj : error : The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. D:\VisualStudio\SharpCompress\sharpcompress\src\SharpCompress\SharpCompress.xproj

D:\VisualStudio\SharpCompress\sharpcompress\test\SharpCompress.Test\SharpCompress.Test.xproj : error : The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. D:\VisualStudio\SharpCompress\sharpcompress\test\SharpCompress.Test\SharpCompress.Test.xproj

@alexandrejh commented on GitHub (Jul 5, 2016): when i try to open the project in my VS 2015 i got this error > D:\VisualStudio\SharpCompress\sharpcompress\src\SharpCompress\SharpCompress.xproj : error : The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. D:\VisualStudio\SharpCompress\sharpcompress\src\SharpCompress\SharpCompress.xproj > > D:\VisualStudio\SharpCompress\sharpcompress\test\SharpCompress.Test\SharpCompress.Test.xproj : error : The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. D:\VisualStudio\SharpCompress\sharpcompress\test\SharpCompress.Test\SharpCompress.Test.xproj
Author
Owner

@adamhathcock commented on GitHub (Jul 5, 2016):

You need the .NET Core Preview 2 tooling that uses xproj. I haven't quite updated to that yet but I will after I return from vacation.

@adamhathcock commented on GitHub (Jul 5, 2016): You need the .NET Core Preview 2 tooling that uses xproj. I haven't quite updated to that yet but I will after I return from vacation.
Author
Owner

@adamhathcock commented on GitHub (Jul 5, 2016):

Right now the code is RC2 but I need to make it RTM for .NET Core and .NET Standard

@adamhathcock commented on GitHub (Jul 5, 2016): Right now the code is RC2 but I need to make it RTM for .NET Core and .NET Standard
Author
Owner

@adamhathcock commented on GitHub (Sep 27, 2016):

You can fix this now that everything is RTM.

http://dot.net

@adamhathcock commented on GitHub (Sep 27, 2016): You can fix this now that everything is RTM. http://dot.net
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#100