Class UploadVerifier
java.lang.Object
com.iizix.server.upload.UploadVerifier
Verifies a completely received upload: decodes it in full (transparently through gzip), sniffs the media type from the first bytes, and checks the decoded byte count against the declared size as it streams - the loop aborts on the first buffer that crosses the declared size, so a gzip bomb costs at most the declared size plus one buffer of decoding, never a full expansion followed by a comparison.
A file is verified with an empty type only when nothing about it claims a type the sniffer knows: a file declared - by its media type or, when that has no signature, by the extension of its name - as a type that has a signature, whose bytes carry no signature at all, fails TYPE_UNVERIFIED, and one whose bytes carry another type's signature fails TYPE_MISMATCH (ruling G-4). Text, CSV and every other type or extension without a signature pass on what they are declared as, as before.
Stateless; runs on whatever thread the service chooses (never the servlet thread).
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe outcome of a verification.Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringFailure reason: the bytes do not decode.static final StringFailure reason: the decoded size differs from the declared size.static final StringFailure reason: the file's bytes are of a sniffable type other than the declared one - the media type, or the extension of the name when the media type has no signature.static final StringFailure reason: the effective type is not permitted by the settings.static final StringFailure reason: the file is declared, by its media type or by the extension of its name, as a type the sniffer knows a signature for, and its bytes carry no known signature.Method Summary
Modifier and TypeMethodDescriptionstatic UploadVerifier.Resultverify(UploadStagingStore store, FileRecord record, UploadLimits limits) Verifies a complete file.
Field Details
TYPE_MISMATCH
Failure reason: the file's bytes are of a sniffable type other than the declared one - the media type, or the extension of the name when the media type has no signature.- See Also:
TYPE_UNVERIFIED
Failure reason: the file is declared, by its media type or by the extension of its name, as a type the sniffer knows a signature for, and its bytes carry no known signature.- See Also:
TYPE_NOT_PERMITTED
Failure reason: the effective type is not permitted by the settings.- See Also:
SIZE_MISMATCH
Failure reason: the decoded size differs from the declared size.- See Also:
CORRUPT
Method Details
verify
public static UploadVerifier.Result verify(UploadStagingStore store, FileRecord record, UploadLimits limits) Verifies a complete file.- Parameters:
store- The store holding the part.record- The file record (declared type and size, compression).limits- The limits (the permitted types, and the types of the reservation's own request, both applied to the verified type).- Returns:
- The result.