/** * 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); } } }
/** * Reads the header of a chunk. If _chunkID is non-null, * it's assumed to have already been read. */ public boolean readHeader (DataInputStream dstrm) throws IOException { StringBuffer id = new StringBuffer(4); for (int i = 0; i < 4; i++) { int ch = ModuleBase.readUnsignedByte (dstrm, _module); if (ch < 32) { String hx = Integer.toHexString (ch); if (hx.length () < 2) { hx = "0" + hx; } _repInfo.setMessage (new ErrorMessage (MessageConstants.ERR_CHUNK_ID_CHAR_INV, MessageConstants.ERR_CHUNK_ID_CHAR_SUB + hx, _module.getNByte ())); _repInfo.setWellFormed (false); return false; } id.append((char) ch); } _chunkID = id.toString (); _size = ModuleBase.readUnsignedInt (dstrm, _module.isBigEndian (), _module); return true; }
if (keyword != null) { msg = new ErrorMessage ("Unexpected null in tEXt chunk"); info.setMessage (msg); info.setWellFormed(false);
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(); } }
msg = new ErrorMessage(Utf8MessageConstants.ERR_UCS4_NOT_UTF8); } else { msg = new ErrorMessage(Utf8MessageConstants.ERR_UTF16LE_NOT_UTF8); return false; } else if (initialBytes[0] == 0xFE && initialBytes[1] == 0xFF) { msg = new ErrorMessage(Utf8MessageConstants.ERR_UTF16BE_NOT_UTF8); info.setMessage(msg); info.setWellFormed(false);
private static boolean checkTypeKey(final PdfDictionary dict, final RepInfo info, final String expctVal, final String typeInvalMess, final String typeNotFoundMess, final String typeNotSimpleMess) { // Get the type key from the dictionary PdfObject typeObj = dict.get(DICT_KEY_TYPE); if (typeObj != null && typeObj instanceof PdfSimpleObject) { // If the type key is not null and is a simple object String typeValue = ((PdfSimpleObject) typeObj).getStringValue(); if (!expctVal.equals(typeValue)) { // If the type key value is not of the expected value info.setWellFormed(false); info.setMessage(new ErrorMessage(typeInvalMess, 0)); return false; } } else { // There's no type key or it's not a simple object // Choose message depending on whether the value is null or of // the wrong type String message = (typeObj == null) ? typeNotFoundMess : typeNotSimpleMess; info.setMessage(new ErrorMessage(message, 0)); info.setWellFormed(false); return false; } return true; }
/** 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); }
int colorIntent = 0; if (_module.isPlteSeen()) { msg = new ErrorMessage ("sRGB chunk not allowed after PLTE chunk"); msg = new ErrorMessage ("sRGB chunk not allowed after IDAT chunk"); msg = new ErrorMessage ("iCCP and sRGB chunks are not allowed in the same file"); msg = new ErrorMessage ("sRGB chunk too short"); msg = new ErrorMessage ("Invalid sRGB rendering intent: " + colorIntent);
/** 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); }
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; }
info.setMessage(new ErrorMessage(e.getMessage())); info.setMessage(new ErrorMessage(MessageConstants.ERR_UNEXPECTED_EXCEPTION + // PDF-HUL-102 e.getClass().getName()));
/** 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; } }
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 }