-
Notifications
You must be signed in to change notification settings - Fork 2
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
Error decoding Xceed Unicode extra field
(0x0x554e)
#13
Comments
Hey @rougemeilland thanks for the very detailed feedback. The issues I had with reverse engineering this field were
I suspect your analysis is spot on. Do you have any small example zip files that fill out the comment field that I could add to my test harness? I can easily create an example by hand, but I'd prefer a file actually generated by the Xceed library code. Any chance you know anything about the other Xceed extra field |
I created a ZIP file with various extra fields added. And I show below the test code that created that ZIP file. This code uses the Xceed ZIP library. using System;
using System.IO;
using System.Text;
using Xceed.Compression;
using Xceed.FileSystem;
using Xceed.Zip;
namespace Experiment001
{
internal class Program
{
// Create a test ZIP file. Specify the path name of the ZIP file in the first command argument.
static void Main(string[] args)
{
var localEncoding = Encoding.GetEncoding("shift_jis");
ZipArchive.DefaultExtraHeaders = ExtraHeaders.None;
ZipArchive.OEMEncodingOverride = localEncoding;
var zipArchiveFile = new DiskFile(args[0]);
var zipArchive = new ZipArchive(zipArchiveFile)
{
DefaultCompressionMethod = CompressionMethod.Deflated,
DefaultCompressionLevel = CompressionLevel.Highest,
DefaultTextEncoding = TextEncoding.Unicode, // Set bit 11 of the general purpose flag.
DefaultUnicodeUsagePolicy = UnicodeUsagePolicy.Always, // Set bit 11 of the general purpose flag even if the entry name and comment are only in the ASCII character set.
};
zipArchive.Comment = $"This is comment for zip archive file '{zipArchive.HostFile.Name}'.";
zipArchive.BeginUpdate();
try
{
{
var file = (ZippedFile)zipArchive.CreateFile($"file_0x554e.txt", true);
file.ExtraHeaders = ExtraHeaders.Unicode; // Add extra field 0x554e to this entry.
file.Comment = $"This is comment for file '{file.FullName}'.";
using (var outputStream = file.OpenWrite(true))
using (var writer = new StreamWriter(outputStream))
{
writer.WriteLine($"Hello, this file is '{file.FullName}'.");
writer.WriteLine($"こんにちは、このファイルは '{file.FullName}' です。");
}
}
{
var file = (ZippedFile)zipArchive.CreateFile($"file_0x5455.txt", true);
file.ExtraHeaders = ExtraHeaders.ExtendedTimeStamp; // Add extra field 0x5455 to this entry.
file.Comment = $"This is comment for file '{file.FullName}'.";
using (var outputStream = file.OpenWrite(true))
using (var writer = new StreamWriter(outputStream))
{
writer.WriteLine($"Hello, this file is '{file.FullName}'.");
writer.WriteLine($"こんにちは、このファイルは '{file.FullName}' です。");
}
}
{
var file = (ZippedFile)zipArchive.CreateFile($"file_0x000a.txt", true);
file.ExtraHeaders = ExtraHeaders.FileTimes; // Add extra field 0x000a to this entry.
file.Comment = $"This is comment for file '{file.FullName}'.";
using (var outputStream = file.OpenWrite(true))
using (var writer = new StreamWriter(outputStream))
{
writer.WriteLine($"Hello, this file is '{file.FullName}'.");
writer.WriteLine($"こんにちは、このファイルは '{file.FullName}' です。");
}
}
}
finally
{
zipArchive.EndUpdate();
}
}
}
} By the way, I have done some research on the .NET version of the Xceed ZIP library.
Unfortunately, I couldn't find any code that deals with the extra field 0x4f4c (Xceed original location extra field). |
Thanks @rougemeilland ! below is the output from a tentative fix I've just applied to Don't see any mention of the
If you have the time could you create another zip file that has 8-bit filenames & comments and also uses the Hmm, Just looking at the Xceed documentation I see there are a couple of I'd do this myself but the Xceed library appears to be a commercial product that I'm not prepared to pay for.
|
Xceed Unicode extra field
(0x0x554e)
I tried various things with the Xceed ZIP library, but the conclusion was that I could not create a ZIP file using The Xceed ZIP library seems to behave as follows.
I came to this conclusion as a result of the following experiment. ExperimentsExperiment 1It is possible to set Experiment 2I tried to set the use of Experiment 3When creating a ZIP file with WinRar, an extra field
WinRar doesn't seem to have the ability to set comments for entries in the first place. Therefore, I could not confirm how ZIP files with the extra field Please note that I have not purchased the Xceed ZIP library yet. It is currently still in the trial period. After some time I should be unable to use it. By the way, there is something that has been bothering me ever since I started using the trial version of the .NET version of the Xceed ZIP library. That is, the Xceed ZIP library is for .NET framework 4. |
Hmmm, that's strange. The two info zip fields The standard way to flag that the filename/comment are encoded in UTF8 these days is to just set the Might give the Xceed trial library a go. Problem is I know nothing about C# and .NET -- Windows coding isn't my thing :-) |
In conclusion, by using Xceed's product, I was able to create a ZIP file containing a mixture of the following three extra fields.
The ZIP files created are attached to this article, so please see the following articles. Next, the history up to that point is shown below. I read the following specifications that you mentioned in the comment the other day. I found it strange that the content was so far removed from the usage of the .NET version of the Xceed ZIP library that I had been using. I decided to get a trial version of the ActiveX version of the Xceed ZIP library and check out the behavior of extra fields.
As you can see in the results above, the
In the ActiveX version, it is possible to ignore specific extended fields by specifying a property called Additionally, I was able to set the general purpose flag bit 11 by changing a property called By the way, the contents of .NET version executable files can be analyzed relatively easily, but it is not practical for anyone other than experts to analyze the contents of ActiveX version executable files (that is, general Windows DLLs). |
Thank you for the very comprehensive write up. Never mind about not getting to the bottom of why the library does what it does. There are plenty of zip libraries out there that do stranger things. If you ever need an example zip file with specific extra fields populated this distribution has a reasonable collection in the test harness -- look in the t/file directory. I also have a larger collection of real zip files that I have collected -over the years - I use them as a torture test for this program. Please shout of you ever need something & I'll see if I have an example available. |
1. Overview
Although I haven't actually run it, I found an error in the way his subroutine
decode_Xceed_unicode
in the scriptzipdetails
was handled, so I would like to report it.2. Extra field
0x554e
formatAs a result of experiments and analysis, it appears that the format of the extra field
0x0x554e
is as follows.2,1 For central directory headers
2.2 For local headers
3. About the contents of script
zipdetails
The comment of the subroutine
decode_Xceed_unicode
in the scriptzipdetails/bin/zipdetails
saysFound the Null prefix
.My guess is that the reason why there appears to be a 2-byte null at the beginning of the entry name is probably because the comment length field in the 8th byte in "2.1 For central directory headers" happens to be 0.
I don't understand the perl language very well, so I don't know how to fix it. sorry.
The text was updated successfully, but these errors were encountered: