From fcb632faa8a51f981ec6065d3e31ced9953f1679 Mon Sep 17 00:00:00 2001 From: PT-ATA No One Date: Wed, 6 Mar 2024 12:32:18 +0000 Subject: [PATCH] Java: forFile throws OutOfMemoryError for files >2GB #383 Tests --- .../integration/RealApiIntegrationTests.java | 9 +++----- .../java/de/gdata/test/unit/Sha256Test.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java b/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java index 6cf717b9..22888530 100644 --- a/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java +++ b/java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import de.gdata.test.unit.Sha256Test; import de.gdata.vaas.ClientCredentialsGrantAuthenticator; import de.gdata.vaas.IAuthenticator; import de.gdata.vaas.ResourceOwnerPasswordGrantAuthenticator; @@ -207,9 +208,7 @@ public void forSha256MultipleUnknownHash() throws Exception { @Test public void forFileSingleMaliciousFile() throws Exception { - var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; - var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); - Files.writeString(tmpFile, eicar); + var tmpFile = Sha256Test.writeEicar(); var vaas = this.getVaasWithCredentials(); var sha256 = new Sha256(tmpFile); @@ -224,9 +223,7 @@ public void forFileSingleMaliciousFile() @Test public void forFileSingleMaliciousFileWithVerdictRequestAttributes() throws Exception { - var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; - var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); - Files.writeString(tmpFile, eicar); + var tmpFile = Sha256Test.writeEicar(); var vaas = this.getVaasWithCredentials(); var sha256 = new Sha256(tmpFile); diff --git a/java/src/test/java/de/gdata/test/unit/Sha256Test.java b/java/src/test/java/de/gdata/test/unit/Sha256Test.java index 3cafd363..275b632d 100644 --- a/java/src/test/java/de/gdata/test/unit/Sha256Test.java +++ b/java/src/test/java/de/gdata/test/unit/Sha256Test.java @@ -5,6 +5,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.NoSuchAlgorithmException; + public class Sha256Test { @Test public void fromValidSha256() { @@ -29,4 +34,21 @@ public void fromInvalidSha256() { new Sha256("1000020f89134d831f48541b2d8ec39397bc99fccf4cc86a3861257dbe6d819d0"); }); } + + @Test + public void getValue_returnsSha256() throws IOException, NoSuchAlgorithmException { + var tmpFile = writeEicar(); + + var sha256 = new Sha256(tmpFile); + Files.deleteIfExists(tmpFile); + + assertEquals("275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f", sha256.getValue()); + } + + public static Path writeEicar() throws IOException { + var eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; + var tmpFile = Path.of(System.getProperty("java.io.tmpdir"), "eicar.txt"); + Files.writeString(tmpFile, eicar); + return tmpFile; + } }