Reviewed verification allocations

- Dependency hashing reuses one read buffer per artifact
- Hash tests cover mixed entry sizes
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-21 09:06:24 -04:00
commit 43cb336b85
2 files changed
+17 -1

No files matched your search

@@ -231,11 +231,11 @@ public final class GenerationBuildRevision {
throw new IOException("Duplicate dependency artifact entry: " + name);
}
}
byte[] buffer = new byte[16 * 1024];
for (Map.Entry<String, ZipEntry> entry : entries.entrySet()) {
update(digest, entry.getKey());
try (InputStream input = zip.getInputStream(entry.getValue())) {
MessageDigest content = digest();
byte[] buffer = new byte[16 * 1024];
int read;
while ((read = input.read(buffer)) != -1) {
content.update(buffer, 0, read);
@@ -58,6 +58,22 @@ public class GenerationBuildRevisionTest {
GenerationBuildRevision.capture(fixture.options(), dependencies)));
}
@Test
public void hashesLargeShortAndEmptyEntriesIndependently() throws Exception {
Path dependency = temporary.newFile("multiple-entries.jar").toPath();
Map<String, String> contents = Map.of("example/Large.class", "abc".repeat(11_000),
"example/Short.class", "tail", "example/Zero.class", "");
try (ZipOutputStream output = new ZipOutputStream(Files.newOutputStream(dependency))) {
for (String name : List.of("example/Zero.class", "example/Short.class", "example/Large.class")) {
output.putNextEntry(new ZipEntry(name));
output.write(contents.get(name).getBytes(StandardCharsets.UTF_8));
output.closeEntry();
}
}
assertEquals("49217af891afa3111d1f70a390acacc8bad700528b61b1ecc5637c060aeb52cd",
GenerationBuildRevision.artifactHash(dependency));
}
@Test
public void rejectsChangedAddedAndDeletedGenerationSources() throws Exception {
Fixture fixture = fixture();