6
6
import software .coley .lljzip .format .ZipPatterns ;
7
7
import software .coley .lljzip .format .model .LocalFileHeader ;
8
8
import software .coley .lljzip .format .model .ZipArchive ;
9
+ import software .coley .lljzip .format .read .ForwardScanZipReader ;
9
10
import software .coley .lljzip .format .read .NaiveLocalFileZipReader ;
10
11
import software .coley .lljzip .format .read .SimpleZipPartAllocator ;
12
+ import software .coley .lljzip .format .read .ZipPartAllocator ;
11
13
import software .coley .lljzip .format .transform .IdentityZipPartMapper ;
12
14
import software .coley .lljzip .format .transform .JvmClassDirectoryMapper ;
13
15
import software .coley .lljzip .format .write .ZipOutputStreamZipWriter ;
@@ -96,8 +98,34 @@ public void testTrickJarPatched(String name) {
96
98
97
99
@ Test
98
100
@ SuppressWarnings ("resource" )
99
- public void testNaiveWithForwardScanningData () {
100
- NaiveLocalFileZipReader strategy = new NaiveLocalFileZipReader (new SimpleZipPartAllocator () {
101
+ public void testReadIgnoringFileLengths () {
102
+ ZipPartAllocator allocator = lengthIgnoringAllocator ();
103
+
104
+ Path path = Paths .get ("src/test/resources/resource-pack-trick-data-ioobe.zip" );
105
+
106
+ // Naive strategy finds the file with the trailing '/'
107
+ NaiveLocalFileZipReader naiveStrategy = new NaiveLocalFileZipReader (allocator );
108
+ ZipArchive zip = assertDoesNotThrow (() -> ZipIO .read (path , naiveStrategy ));
109
+ assertNotNull (zip .getLocalFileByName ("assets/luxbl/lang/en_us.json/" ), "Missing 'en_us' file" );
110
+
111
+ // Standard strategy finds it, but its authoritative CEN defines the file name to not include the trailing '/'
112
+ ForwardScanZipReader forwardStrategy = new ForwardScanZipReader (allocator );
113
+ zip = assertDoesNotThrow (() -> ZipIO .read (path , forwardStrategy ));
114
+ assertNotNull (zip .getLocalFileByName ("assets/luxbl/lang/en_us.json" ), "Missing 'en_us' file" );
115
+ }
116
+
117
+ @ Test
118
+ @ SuppressWarnings ("resource" )
119
+ public void testTrailingSlashTransform () {
120
+ // The 'JvmClassDirectoryMapper' maps 'Name.class/' paths to 'Name.class'
121
+ Path path = Paths .get ("src/test/resources/hello-secret-trailing-slash.jar" );
122
+ ZipArchive zip = assertDoesNotThrow (() -> ZipIO .readStandard (path )
123
+ .withMapping (new JvmClassDirectoryMapper (new IdentityZipPartMapper ())));
124
+ assertNotNull (zip .getLocalFileByName ("Hello.class" ), "Trailing slash was not patched" );
125
+ }
126
+
127
+ private static ZipPartAllocator lengthIgnoringAllocator () {
128
+ return new SimpleZipPartAllocator () {
101
129
@ Nonnull
102
130
@ Override
103
131
public LocalFileHeader newLocalFileHeader () {
@@ -114,20 +142,6 @@ protected MemorySegmentData readFileData(@Nonnull MemorySegment data, long heade
114
142
}
115
143
};
116
144
}
117
- });
118
-
119
- Path path = Paths .get ("src/test/resources/resource-pack-trick-data-ioobe-no-end.zip" );
120
- ZipArchive zip = assertDoesNotThrow (() -> ZipIO .read (path , strategy ));
121
- assertNotNull (zip .getLocalFileByName ("pack.mcmeta" ), "IOOBE not patched" );
122
- }
123
-
124
- @ Test
125
- @ SuppressWarnings ("resource" )
126
- public void testTrailingSlashTransform () {
127
- // The 'JvmClassDirectoryMapper' maps 'Name.class/' paths to 'Name.class'
128
- Path path = Paths .get ("src/test/resources/hello-secret-trailing-slash.jar" );
129
- ZipArchive zip = assertDoesNotThrow (() -> ZipIO .readStandard (path )
130
- .withMapping (new JvmClassDirectoryMapper (new IdentityZipPartMapper ())));
131
- assertNotNull (zip .getLocalFileByName ("Hello.class" ), "Trailing slash was not patched" );
145
+ };
132
146
}
133
147
}
0 commit comments