File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments