diff --git a/src/main/java/org/verapdf/rest/resources/ValidateResource.java b/src/main/java/org/verapdf/rest/resources/ValidateResource.java index 7bc4cf95..55c79dc1 100644 --- a/src/main/java/org/verapdf/rest/resources/ValidateResource.java +++ b/src/main/java/org/verapdf/rest/resources/ValidateResource.java @@ -112,6 +112,10 @@ public static InputStream validateXml(@Parameter(description = "the String id of style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, null, FormatOption.XML); } @@ -153,6 +157,10 @@ public static InputStream validateXml(@Parameter(description = "the String id of style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, sha1Hex, FormatOption.XML); } @@ -203,6 +211,10 @@ public static InputStream validateJson(@Parameter(description = "the String id o style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, null, FormatOption.JSON); } @@ -234,6 +246,10 @@ public static InputStream validateJson(@Parameter(description = "the String id o style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, sha1Hex, FormatOption.JSON); } @@ -271,6 +287,10 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId, style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, null, FormatOption.HTML); } @@ -299,6 +319,10 @@ public static InputStream validateHtml(@PathParam("profileId") String profileId, style = ParameterStyle.FORM, description = "an InputStream of the PDF to be validated") @FormDataParam("file") InputStream uploadedInputStream, @Parameter(hidden = true) @FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) { + if (contentDispositionHeader == null) { + throw new BadRequestException("File is empty"); + } + return validate(uploadedInputStream, contentDispositionHeader.getFileName(), profileId, sha1Hex, FormatOption.HTML); } @@ -322,6 +346,10 @@ public static void setMaxFileSize(Integer maxFileSize) { private static InputStream validate(InputStream uploadedInputStream, String fileName, String profileId, String sha1Hex, FormatOption formatOption) { + if (fileName == null) { + throw new BadRequestException("File name is empty"); + } + SeekableInputStream seekableInputStream = createInputStream(uploadedInputStream, sha1Hex); PDFAFlavour flavour = PDFAFlavour.byFlavourId(profileId); ValidatorConfig validatorConfig = configManager.getValidatorConfig();