/** * Performs the appropriate disparagement act on a RepInfo * object. For a PdfInvalidException, this is to call * <code>setValid (false)</code>. */ @Override public void disparage (RepInfo info) { info.setWellFormed (false); }
/** Utility error reporting function for a subbox overrunning * its superbox. * Sets the RepInfo's wellFormed flag to <code>false</code>. */ protected void superboxOverrun () { _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_SUPERBOX_OVERRUN + getSelfPropName (), _module.getFilePos ())); _repInfo.setWellFormed (false); }
/** Utility error reporting function for box in a context * (superbox or lack thereof) which is not permitted. * Sets the RepInfo's wellFormed flag to <code>false</code>. */ protected void wrongBoxContext () { _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_BOX_CONTEXT_INVALID + getSelfPropName (), _module.getFilePos ())); _repInfo.setWellFormed (false); }
protected boolean readHeader(RepInfo info) { int i; int ch; boolean valid = true; try { for (i = 0; i < 2; i++) { ch = readUnsignedByte(_dstream, this); if (ch != sigByte[i]) { valid = false; break; } } } catch (IOException e) { valid = false; } if (!valid) { info.setMessage(new ErrorMessage(MessageConstants.ERR_HEADER_INVALID, 0)); info.setWellFormed(false); return false; } return true; }
/** Utility error reporting function for a subbox underrunning * its superbox. * Sets the RepInfo's wellFormed flag to <code>false</code>. */ protected void superboxUnderrun () { _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_SUPERBOX_UNDERRUN + getSelfPropName (), _module.getFilePos ())); _repInfo.setWellFormed (false); }
/** Utility error reporting function for incorrect box length. * Sets the RepInfo's wellFormed flag to <code>false</code>. */ protected void wrongBoxSize () { _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_BOX_SIZE_INVALID + getSelfPropName (), _module.getFilePos ())); _repInfo.setWellFormed (false); }
/** Utility error reporting function for a box which is * expected to have subboxes, but doesn't. */ protected void emptyBox () { _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_BOX_CONTENT_EMPTY, "Box type = " + getSelfPropName (), _module.getFilePos ())); _repInfo.setWellFormed (false); }
/** Reads the file type. * Broken out from parse(). * If it is not a valid file type, returns false. */ protected boolean readFileType (RepInfo info) throws IOException { String typ = read4Chars (_dstream); bytesRemaining -= 4; if ("AIFF".equals (typ)) { fileType = AIFFTYPE; return true; } else if ("AIFC".equals (typ)) { fileType = AIFCTYPE; _aesMetadata.setFormat ("AIFF-C"); _aesMetadata.setSpecificationVersion ("Draft 1991-08-26"); return true; } else { info.setMessage (new ErrorMessage (MessageConstants.ERR_FORM_CHUNK_NOT_AAIF, _nByte)); info.setWellFormed (RepInfo.FALSE); return false; } }
/** Reads a chunk and puts information into the superchunk's * Exif property. * * @return <code>false</code> if the chunk is structurally * invalid, otherwise <code>true</code> */ public boolean readChunk(RepInfo info) throws IOException { WaveModule module = (WaveModule) _module; if (bytesLeft != 4) { info.setMessage (new ErrorMessage (MessageConstants.ERR_EXIF_VER_CHUNK_LEN_WRNG)); info.setWellFormed (false); return false; } byte[] buf = new byte[4]; ModuleBase.readByteBuf (_dstream, buf, module); String txt = new String (buf); module.getExifInfo ().setExifVersion(txt); return true; }
/** Puts the item's error message into the RepInfo * object, and affects the wellFormed and valid * flags as required. Once it's determined that * a document is not well-formed, error elements indicating * only invalidity will be ignored. However, additional * messages that indicate the current level of badness * (not well-formed or invalid) will continue to be reported.*/ public void reportError (RepInfo info) { // If we're already not well-formed and the error element // is for invalidity, don't bother with it. if (info.getWellFormed() == RepInfo.FALSE && !_illFormed) { return; } info.setMessage (new ErrorMessage (_message, _image)); if (_illFormed) { info.setWellFormed (false); } else { info.setValid(false); } } }
/** Common code to call at the start of every processChunk method. */ public void processChunkCommon (RepInfo info) throws PNGException { if (ancillary && !duplicateAllowed) { if (_module.isChunkSeen(chunkType)) { ErrorMessage msg = new ErrorMessage ("Multiple " + chunkTypeString() + " chunks are not allowed"); info.setMessage (msg); info.setWellFormed (false); throw new PNGException ("Duplicate chunk"); } _module.setChunkSeen (chunkType); } int[] chunkTypeVal = chunkTypeBytes(); for (int i = 0; i < 4; i++) { crc.update(chunkTypeVal[i]); } }
@Override public void checkSignatures (File file, InputStream stream, RepInfo info) throws IOException { info.setFormat (_format[0]); info.setMimeType (_mimeType[0]); info.setModule (this); boolean checkIsGzip = GzipReader.isGzipped(new ByteCountingPushBackInputStream(stream, GzipReader.DEFAULT_INPUT_BUFFER_SIZE)); if (checkIsGzip) { info.setSigMatch(_name); } else { info.setWellFormed (false); } }
protected boolean readPageLabelTree(RepInfo info) { // the page labels number tree is optional. try { if (_pageLabelDict != null) { _pageLabelRoot = new PageLabelNode(this, null, _pageLabelDict); _pageLabelRoot.buildSubtree(); } } catch (PdfException e) { e.disparage(info); info.setMessage(new ErrorMessage (e.getMessage(), _parser.getOffset())); // Continue parsing if it's only invalid return (e instanceof PdfInvalidException); } catch (Exception e) { info.setWellFormed(false); info.setMessage(new ErrorMessage(MessageConstants.ERR_UNEXPECTED_EXCEPTION + // PDF-HUL-99 e.getClass().getName())); return false; } return true; // always succeeds }
/** Process the chunk. We don't analyze or report the data, but * we enforce the requirement that IDAT chunks must be consecutive. */ public void processChunk(RepInfo info) throws Exception { processChunkCommon(info); _module.setIdatSeen(true); if (_module.isIdatFinished()) { ErrorMessage msg = new ErrorMessage("IDAT chunks are not consecutive in file"); info.setMessage(msg); info.setWellFormed(false); throw new PNGException ("Misplaced IDAT chunk"); } for (int i = 0; i <length; i++) { readUnsignedByte(); } }
/** Reads a chunk and puts an AudioRecording property into * the RepInfo object. * * @return <code>false</code> if the chunk is structurally * invalid, otherwise <code>true</code> */ public boolean readChunk(RepInfo info) throws IOException { AiffModule module = (AiffModule) _module; if (bytesLeft != 24) { // This chunk must always have exactly 24 bytes data info.setMessage (new ErrorMessage (MessageConstants.ERR_REC_CHUNK_WRONG_SIZE, module.getNByte ())); info.setWellFormed (false); return false; } byte[] buf = new byte[24]; ModuleBase.readByteBuf (_dstream, buf, module); module.addAiffProperty (new Property ("AudioRecording", PropertyType.BYTE, PropertyArity.ARRAY, buf)); return true; }
protected boolean readExtBlock (RepInfo info) throws IOException { int subtype = readUnsignedByte (_dstream, this); switch (subtype) { case APPLICATION_EXT: return readAppExtension (info); case COMMENT_EXT: return readCommentExtension (info); case GRAPHIC_CONTROL_EXT: return readGraphicsCtlBlock (info); case PLAIN_TEXT_EXT: return readPlainTextExtension (info); default: info.setWellFormed (RepInfo.FALSE); info.setMessage (new ErrorMessage (MessageConstants.ERR_EXTENSION_BLOCK_TYPE_UNKNOWN, "Type = " + subtype, _nByte)); return false; } }
@Override public void checkSignatures (File file, InputStream stream, RepInfo info) throws IOException { info.setFormat (_format[0]); info.setMimeType (_mimeType[0]); info.setModule (this); ByteCountingPushBackInputStream pbin = new ByteCountingPushBackInputStream(stream, GzipReader.DEFAULT_INPUT_BUFFER_SIZE); // First try warc uncompressed boolean checkIsWarc = WarcReaderFactory.isWarcFile(pbin); if (checkIsWarc) { info.setSigMatch(_name); return; } // Then try warc compressed boolean checkIsGzip = GzipReader.isGzipped(pbin); if (checkIsGzip) { info.setSigMatch(_name); return; } // Not a warc or a gzip info.setWellFormed (false); }
protected boolean parseHeader(RepInfo info) throws IOException { PdfHeader header = PdfHeader.parseHeader(_parser); if (header == null) { info.setWellFormed(false); info.setMessage(new ErrorMessage(MessageConstants.ERR_PDF_HEADER_MISSING, 0L)); // PDF-HUL-137 return false; } if (!header.isVersionValid()) { info.setValid(false); info.setMessage(new ErrorMessage(MessageConstants.ERR_PDF_MINOR_INVALID, 0L)); // PDF-HUL-148 } _version = header.getVersionString(); _pdfACompliant = header.isPdfACompliant(); info.setSigMatch(_name); return true; }
protected boolean readFileTypeBox(RepInfo info) throws IOException { BoxHeader hdr = new BoxHeader(this, _dstream); hdr.readHeader(); // 8 bytes have been read if (!"ftyp".equals(hdr.getType())) { info.setMessage(new ErrorMessage(MessageConstants.ERR_FILE_TYPE_BOX_POSITION_INVALID + hdr.getType(), _nByte)); info.setWellFormed(false); return false; } FileTypeBox box = new FileTypeBox(_raf); box.setBoxHeader(hdr); box.setDataInputStream(_dstream); box.setRandomAccessFile(_raf); box.setModule(this); box.setRepInfo(info); if (!box.readBox()) { return false; } return true; }
public void processChunk(RepInfo info) throws Exception { ErrorMessage msg = null; processChunkCommon(info); if (_module.isPlteSeen()) { msg = new ErrorMessage ("Multiple PLTE chunks are not allowed"); } _module.setPlteSeen(true); if (_module.isIdatSeen()) { msg = new ErrorMessage("PLTE chunk is not allowed after first IDAT chunk"); } if ((length % 3) != 0) { // must be a multiple of 3 bytes msg = new ErrorMessage("Invalid PLTE chunk length " + length); } if (msg != null) { info.setMessage(msg); info.setWellFormed(false); throw new PNGException ("PLTE chunk error"); } for (int i = 0; i <length; i++) { // We don't care about the contents readUnsignedByte(); } }