Skip to content

Commit 64d1677

Browse files
authored
Merge pull request #36118 from bdach/zip-magic
2 parents 2d06c2b + 95233fc commit 64d1677

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

osu.Game/Utils/ZipUtils.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ public static bool IsZipArchive(MemoryStream stream)
2323
{
2424
}
2525
}
26-
}
2726

28-
return true;
27+
// aside from opening every zip entry not failing, we also require there to *be* at least one entry.
28+
// if there are no entries, the best case is that it's an actual empty zip
29+
// and as such probably useless to whatever wants to use it later.
30+
// the worst case is that it's actually *not* a zip and instead a stream of binary
31+
// which *accidentally* happened to contain the magic sequence of bytes for the zip header (50 4b 05 06),
32+
// and if that's the case, then we are *misclassifying* it as a zip by returning `true` unconditionally.
33+
return arc.Entries.Count > 0;
34+
}
2935
}
3036
catch (Exception)
3137
{
@@ -52,9 +58,15 @@ public static bool IsZipArchive(string path)
5258
{
5359
}
5460
}
55-
}
5661

57-
return true;
62+
// aside from opening every zip entry not failing, we also require there to *be* at least one entry.
63+
// if there are no entries, the best case is that it's an actual empty zip
64+
// and as such probably useless to whatever wants to use it later.
65+
// the worst case is that it's actually *not* a zip and instead a stream of binary
66+
// which *accidentally* happened to contain the magic sequence of bytes for the zip header (50 4b 05 06),
67+
// and if that's the case, then we are *misclassifying* it as a zip by returning `true` unconditionally.
68+
return arc.Entries.Count > 0;
69+
}
5870
}
5971
catch (Exception)
6072
{

0 commit comments

Comments
 (0)