File tree 1 file changed +16
-5
lines changed
1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change 9
9
using System . Linq ;
10
10
using System . Text ;
11
11
using Microsoft . Toolkit . HighPerformance ;
12
+ using osu . Framework . Extensions ;
12
13
using osu . Framework . IO . Stores ;
13
14
using SharpCompress . Archives . Zip ;
14
15
using SharpCompress . Common ;
@@ -54,12 +55,22 @@ public override Stream GetStream(string name)
54
55
if ( entry == null )
55
56
return null ;
56
57
57
- var owner = MemoryAllocator . Default . Allocate < byte > ( ( int ) entry . Size ) ;
58
-
59
58
using ( Stream s = entry . OpenEntryStream ( ) )
60
- s . ReadExactly ( owner . Memory . Span ) ;
61
-
62
- return new MemoryOwnerMemoryStream ( owner ) ;
59
+ {
60
+ if ( entry . Size > 0 )
61
+ {
62
+ var owner = MemoryAllocator . Default . Allocate < byte > ( ( int ) entry . Size ) ;
63
+ s . ReadExactly ( owner . Memory . Span ) ;
64
+ return new MemoryOwnerMemoryStream ( owner ) ;
65
+ }
66
+
67
+ // due to a sharpcompress bug (https://github.com/adamhathcock/sharpcompress/issues/88),
68
+ // in rare instances the `ZipArchiveEntry` will not contain a correct `Size` but instead report 0.
69
+ // this would lead to the block above reading nothing, and the game basically seeing an archive full of empty files.
70
+ // since the bug is years old now, and this is a rather rare situation anyways (reported once in years),
71
+ // work around this locally by falling back to reading as many bytes as possible and using a standard non-pooled memory stream.
72
+ return new MemoryStream ( s . ReadAllRemainingBytesToArray ( ) ) ;
73
+ }
63
74
}
64
75
65
76
public override void Dispose ( )
You can’t perform that action at this time.
0 commit comments