/** * Processes a parsing exception. An ill-formed piece * of XML will get a fatalError (I think), so we can assume * that any error here indicates only invalidity. */ public void error(SAXParseException e) { _valid = false; if (_nErrors == MAXERRORS) { _messages.add (new InfoMessage ( MessageFormat.format(MessageConstants.WRN_TOO_MANY_MESSAGES, MAXERRORS))); } else if (_nErrors < MAXERRORS) { int line = e.getLineNumber(); int col = e.getColumnNumber(); _messages.add (new ErrorMessage ( MessageFormat.format(MessageConstants.ERR_SAX_EXCEPTION,e.getMessage ().toString ()), "Line = " + line + ", Column = " + col)); } ++_nErrors; }
protected void dupChunkError (RepInfo info, String chunkName) { info.setMessage (new ErrorMessage (MessageConstants.ERR_MULTI_CHUNK_NOT_PERM + chunkName + MessageConstants.ERR_MULTI_CHUNK_NOT_PERM_2, _nByte)); info.setValid (false); } }
/** Report an instance of invalidity. */ protected void reportInvalid(String s, RepInfo info) { info.setMessage(new ErrorMessage(s)); info.setValid(false); }
/** Reports a duplicate chunk. */ protected void dupChunkError(RepInfo info, String chunkName) { info.setMessage(new ErrorMessage(MessageConstants.ERR_CHUNK_DUP + chunkName, _nByte)); info.setValid(false); }
/** * Go through all the IFD's, calling checkIFDValidity on each one that is a * standard IFD. (Private IFD's have different requirements, and for the * moment aren't checked here.) If any of them are invalid, set info's valid * field to false. Validity problems are non-fatal, and more information is * better, so we keep going with all IFDs even if we find problems. */ protected void checkValidity(List<IFD> ifds, RepInfo info) { _logger.info("TiffModule checking validity of IFDs"); ListIterator<IFD> iter = ifds.listIterator(); while (iter.hasNext()) { try { IFD ifd = iter.next(); if (ifd instanceof TiffIFD) { checkValidity((TiffIFD) ifd, info); } } catch (TiffException e) { info.setMessage(new ErrorMessage(e.getMessage(), e.getOffset())); info.setValid(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); }
/** 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 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; }
/** Lookup an IFD tag. */ public void lookupTag(int tag, int type, long count, long value) throws TiffException { try { if (tag == INTEROPERABILITYINDEX) { checkType (tag, type, ASCII); _interoperabilityIndex = readASCII(count, value); } else { _info.setMessage (new ErrorMessage(MessageConstants.ERR_EXIF_INTER_IFD_UNK, MessageConstants.TAG_SUB_MESS + tag, value)); } } catch (IOException e) { throw new TiffException(MessageConstants.ERR_TAG_IO_READ + tag, value); } } }
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; }
public void processChunk(RepInfo info) throws Exception { processChunkCommon(info); _module.setIendSeen(true); // This chunk is supposed to have a length of 0. // If it's bigger, eat the extra bytes and declare the // file invalid but not ill-formed. if (length > 0) { ErrorMessage msg = new ErrorMessage("IEND chunk is not empty"); info.setMessage (msg); info.setValid (false); for (int i = 0; i < length; i++) { readUnsignedByte(); } } }
/** 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]); } }
/** 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(); } }
protected void readDTT(RepInfo info) throws IOException { readUnsignedShort(_dstream); if (_tiling == null) { info.setMessage(new ErrorMessage( MessageConstants.ERR_DTT_SEG_MISSING_PREV_DTI, _nByte)); info.setValid(false); return; } long vertScale = readUnsignedInt(_dstream); long horScale = readUnsignedInt(_dstream); long vertOffset = readUnsignedInt(_dstream); long horOffset = readUnsignedInt(_dstream); _tiling.addTile(vertScale, horScale, vertOffset, horOffset); _seenJPEGL = false; // Not permitted under JPEG-L }
private void doCloseTag (JHCloseTag tag, RepInfo info) { String name = tag.getName (); // Dig down into the stack till we find an element which // matches this. If there's none, report the document // as not well formed. Also allow for the special case // of an empty body. (An empty head is illegal.) int idx = elementStack.search (name); if (idx == -1) { info.setMessage (new ErrorMessage (MessageConstants.ERR_HTML_CLOSED_TAG_NO_OPEN, "Name = " + name + ", Line = " + tag.getLine () + ", Column = " + tag.getColumn ())); info.setValid (false); } else { // Pop the stack down to the level of the matching tag. elementStack.popTo (idx); } }
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; } }
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; }