|
7 | 7 | import software.coley.llzip.format.model.LocalFileHeader; |
8 | 8 | import software.coley.llzip.format.model.ZipArchive; |
9 | 9 | import software.coley.llzip.format.model.ZipPart; |
| 10 | +import software.coley.llzip.format.read.ForwardScanZipReaderStrategy; |
10 | 11 | import software.coley.llzip.format.read.JvmZipReaderStrategy; |
11 | 12 | import software.coley.llzip.util.ByteDataUtil; |
12 | 13 |
|
@@ -107,23 +108,30 @@ public void testLocalHeaderDetectMismatch() { |
107 | 108 | Path path = Paths.get("src/test/resources/hello-secret-0-length-locals.jar"); |
108 | 109 |
|
109 | 110 | try { |
110 | | - ZipArchive zipJvm = ZipIO.readJvm(path); |
111 | | - assertNotNull(zipJvm); |
| 111 | + // The 'standard' strategy does not adopt CEN values when reading local entries. |
| 112 | + // The 'jvm' strategy does. |
| 113 | + ZipArchive zipStd = ZipIO.readStandard(path); |
| 114 | + assertNotNull(zipStd); |
112 | 115 |
|
113 | | - LocalFileHeader hello = zipJvm.getLocalFileByName("Hello.class"); |
| 116 | + LocalFileHeader hello = zipStd.getLocalFileByName("Hello.class"); |
114 | 117 | assertNotNull(hello); |
115 | 118 |
|
116 | 119 | // The local file header says the contents are 0 bytes, but the central header has the real length |
117 | 120 | assertTrue(hello.hasDifferentValuesThanCentralDirectoryHeader()); |
118 | 121 |
|
119 | 122 | // The solution to differing values is to adopt values in the reader strategy |
120 | | - ZipArchive zipJvmAndAdopt = ZipIO.read(path, new JvmZipReaderStrategy() { |
| 123 | + ZipArchive zipStdAndAdopt = ZipIO.read(path, new ForwardScanZipReaderStrategy() { |
121 | 124 | @Override |
122 | 125 | public void postProcessLocalFileHeader(LocalFileHeader file) { |
123 | 126 | file.adoptLinkedCentralDirectoryValues(); |
124 | 127 | } |
125 | 128 | }); |
126 | | - LocalFileHeader helloAdopted = zipJvmAndAdopt.getLocalFileByName("Hello.class"); |
| 129 | + LocalFileHeader helloAdopted = zipStdAndAdopt.getLocalFileByName("Hello.class"); |
| 130 | + assertFalse(helloAdopted.hasDifferentValuesThanCentralDirectoryHeader()); |
| 131 | + |
| 132 | + // Alternatively, just use the JVM strategy |
| 133 | + ZipArchive zipJvm = ZipIO.readJvm(path); |
| 134 | + helloAdopted = zipJvm.getLocalFileByName("Hello.class"); |
127 | 135 | assertFalse(helloAdopted.hasDifferentValuesThanCentralDirectoryHeader()); |
128 | 136 | } catch (IOException ex) { |
129 | 137 | fail(ex); |
|
0 commit comments