Skip to content

Commit

Permalink
Fix max file size issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov authored and bdoubrov committed May 3, 2024
1 parent 8425d9d commit 39573d0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/verapdf/rest/resources/ValidateResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.InternalServerErrorException;
Expand Down Expand Up @@ -61,6 +62,9 @@
* @author <a href="mailto:[email protected]">Carl Wilson</a>
*/
public class ValidateResource {

private static final Logger LOGGER = Logger.getLogger(ValidateResource.class.getCanonicalName());

private static final String PARAM_PROFILE_DESC = "the String id of the PDF Specification to validate against. " +
"Possible values: auto, 1b, 1a, 2b, 2a, 2u, 3b, 3a, 3u, 4, 4e, 4f, ua1, ua2, wt1a or wt1r. " +
"Selecting 'auto' allows the validator to detect and apply the appropriate specification from the PDF metadata.";
Expand Down Expand Up @@ -152,7 +156,13 @@ public static Response validate(
}

public static void setMaxFileSize(Integer maxFileSize) {
ValidateResource.maxFileSize = maxFileSize;
int maxValue = Integer.MAX_VALUE / CONVERTER_MB_TO_B;
if (maxFileSize < maxValue && maxFileSize > 0) {
maxValue = maxFileSize;
} else {
LOGGER.log(Level.WARNING, "Incorrect value of maxFileSize parameter. maxFileSize set to " + maxValue);
}
ValidateResource.maxFileSize = maxValue;
}

private static InputStream validateFile(InputStream uploadedInputStream,
Expand Down

0 comments on commit 39573d0

Please sign in to comment.