Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[class-parse] Ignore module-info.class file. #1093

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/Xamarin.Android.Tools.Bytecode/ClassPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ public void Load (Stream jarStream, bool leaveOpen = false)

using (var jar = CreateZipArchive (jarStream, leaveOpen)) {
foreach (var entry in jar.Entries) {
if (entry.Length == 0)
if (!ShouldLoadEntry (entry))
continue;
using (var s = entry.Open ()) {
if (!ClassFile.IsClassFile (s) || entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
continue;
}

using (var s = entry.Open ()) {
try {
var c = new ClassFile (s);
Expand All @@ -85,6 +82,22 @@ public void Load (Stream jarStream, bool leaveOpen = false)
}
}

static bool ShouldLoadEntry (ZipArchiveEntry entry)
{
if (entry.Length == 0)
return false;

if (entry.Name == "module-info.class")
return false;

if (entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
return false;

using var s = entry.Open ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of #1092, should this instead use BufferedStream?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want it in this case, as we are reading a single value from the Stream and then closing it. If we use BufferedStream it would need to read xKB into the buffer instead of the single 4 byte read.


return ClassFile.IsClassFile (s);
}

static ZipArchive CreateZipArchive (Stream jarStream, bool leaveOpen)
{
var encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false);
Expand Down