Skip to content

Commit

Permalink
Java: forFile throws OutOfMemoryError for files >2GB #383
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
ata-no-one authored and pstadermann committed Mar 11, 2024
1 parent a9daa50 commit fcb632f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions java/src/test/java/de/gdata/test/unit/Sha256Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}

0 comments on commit fcb632f

Please sign in to comment.