|
32 | 32 | import org.junit.jupiter.api.BeforeEach; |
33 | 33 | import org.junit.jupiter.api.AfterEach; |
34 | 34 | import org.junit.jupiter.api.Test; |
| 35 | +import org.junit.jupiter.params.ParameterizedTest; |
| 36 | +import org.junit.jupiter.params.provider.ValueSource; |
35 | 37 |
|
36 | 38 | import java.io.*; |
37 | 39 | import java.nio.ByteBuffer; |
@@ -71,7 +73,7 @@ public class EndOfCenValidation { |
71 | 73 | private static final int ENDSIZ = ZipFile.ENDSIZ; // Offset of CEN size field within ENDHDR |
72 | 74 | private static final int ENDOFF = ZipFile.ENDOFF; // Offset of CEN offset field within ENDHDR |
73 | 75 | // Maximum allowed CEN size allowed by ZipFile |
74 | | - private static int MAX_CEN_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; |
| 76 | + private static final int MAX_CEN_SIZE = ArraysSupport.SOFT_MAX_ARRAY_LENGTH; |
75 | 77 |
|
76 | 78 | // Expected message when CEN size does not match file size |
77 | 79 | private static final String INVALID_CEN_BAD_SIZE = "invalid END header (bad central directory size)"; |
@@ -170,8 +172,15 @@ public void shouldRejectInvalidCenOffset() throws IOException { |
170 | 172 | * |
171 | 173 | * @throws IOException if an error occurs |
172 | 174 | */ |
173 | | - @Test |
174 | | - public void shouldRejectBadTotalEntries() throws IOException { |
| 175 | + @ParameterizedTest |
| 176 | + @ValueSource(longs = { |
| 177 | + -1, // Negative |
| 178 | + Long.MIN_VALUE, // Very negative |
| 179 | + 0x3B / 3L - 1, // Cannot fit in test ZIP's CEN |
| 180 | + MAX_CEN_SIZE / 3 + 1, // Too large to allocate int[] entries array |
| 181 | + Long.MAX_VALUE // Unreasonably large |
| 182 | + }) |
| 183 | + public void shouldRejectBadTotalEntries(long totalEntries) throws IOException { |
175 | 184 | /** |
176 | 185 | * A small ZIP using the ZIP64 format. |
177 | 186 | * |
@@ -267,7 +276,7 @@ public void shouldRejectBadTotalEntries() throws IOException { |
267 | 276 | ByteBuffer buf = ByteBuffer.wrap(zipBytes).order(ByteOrder.LITTLE_ENDIAN); |
268 | 277 | // Offset of the 'total entries' in the 'ZIP64 END CENTRAL DIR' record |
269 | 278 | // Update ZIP64 entry count to a value which cannot possibly fit in the small CEN |
270 | | - buf.putLong(0x94, MAX_CEN_SIZE / 3); |
| 279 | + buf.putLong(0x94, totalEntries); |
271 | 280 | // The corresponding END field needs the ZIP64 magic value |
272 | 281 | buf.putShort(0xCA, (short) 0xFFFF); |
273 | 282 | // Write the ZIP to disk |
|
0 commit comments