Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 824BB17709 for ; Tue, 20 Jan 2015 18:45:11 +0000 (UTC) Received: (qmail 47152 invoked by uid 500); 20 Jan 2015 18:45:11 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 47131 invoked by uid 500); 20 Jan 2015 18:45:11 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 47121 invoked by uid 99); 20 Jan 2015 18:45:11 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jan 2015 18:45:11 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id EF0D4AC07BD; Tue, 20 Jan 2015 18:45:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1653333 - /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java Date: Tue, 20 Jan 2015 18:45:10 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150120184510.EF0D4AC07BD@hades.apache.org> Author: tilman Date: Tue Jan 20 18:45:10 2015 New Revision: 1653333 URL: http://svn.apache.org/r1653333 Log: PDFBOX-2613: validate /N entry against ICC profiles; split validateICCProfile() method Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java?rev=1653333&r1=1653332&r2=1653333&view=diff ============================================================================== --- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java (original) +++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/CatalogValidationProcess.java Tue Jan 20 18:45:10 2015 @@ -104,6 +104,7 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.cos.COSNumber; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentCatalog; @@ -334,7 +335,8 @@ public class CatalogValidationProcess ex String outputConditionIdentifier = outputIntentDict .getString(OUTPUT_INTENT_DICTIONARY_KEY_OUTPUT_CONDITION_IDENTIFIER); if (outputConditionIdentifier == null) - {// empty string is authorized (it may be an application specific value) + { + // empty string is authorized (it may be an application specific value) addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "The OutputIntentCondition is missing")); continue; @@ -424,39 +426,19 @@ public class CatalogValidationProcess ex } ICC_Profile iccp = ICC_Profile.getInstance(stream.getByteArray()); - PreflightConfiguration config = ctx.getConfig(); - // check the ICC Profile version (6.2.2) - if (iccp.getMajorVersion() == 2) + + if (!validateICCProfileNEntry(stream, ctx, iccp)) { - if (iccp.getMinorVersion() > 0x40) - { - // in PDF 1.4, max version is 02h.40h (meaning V 3.5) - // see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 : - // The current profile version number is "2.4.0" (encoded as 02400000h") - ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, - "Invalid version of the ICCProfile"); - error.setWarning(config.isLazyValidation()); - addValidationError(ctx, error); - return; - } // else OK + return; } - else if (iccp.getMajorVersion() > 2) + if (!validateICCProfileVersion(iccp, ctx)) { - // in PDF 1.4, max version is 02h.40h (meaning V 3.5) - // see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 : - // The current profile version number is "2.4.0" (encoded as 02400000h" - ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, - "Invalid version of the ICCProfile"); - error.setWarning(config.isLazyValidation()); - addValidationError(ctx, error); return; - } // else seems less than 2, so correct - + } if (ctx.getIccProfileWrapper() == null) { ctx.setIccProfileWrapper(new ICCProfileWrapper(iccp)); } - } catch (IllegalArgumentException e) { @@ -469,4 +451,71 @@ public class CatalogValidationProcess ex throw new ValidationException("Unable to parse the ICC Profile.", e); } } + + private boolean validateICCProfileVersion(ICC_Profile iccp, PreflightContext ctx) + { + PreflightConfiguration config = ctx.getConfig(); + + // check the ICC Profile version (6.2.2) + if (iccp.getMajorVersion() == 2) + { + if (iccp.getMinorVersion() > 0x40) + { + // in PDF 1.4, max version is 02h.40h (meaning V 3.5) + // see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 : + // The current profile version number is "2.4.0" (encoded as 02400000h") + ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, + "Invalid version of the ICCProfile"); + error.setWarning(config.isLazyValidation()); + addValidationError(ctx, error); + return false; + } + // else OK + } + else if (iccp.getMajorVersion() > 2) + { + // in PDF 1.4, max version is 02h.40h (meaning V 3.5) + // see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 : + // The current profile version number is "2.4.0" (encoded as 02400000h" + ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, + "Invalid version of the ICCProfile"); + error.setWarning(config.isLazyValidation()); + addValidationError(ctx, error); + return false; + } + // else seems less than 2, so correct + return true; + } + + private boolean validateICCProfileNEntry(PDStream stream, PreflightContext ctx, ICC_Profile iccp) + { + COSDictionary streamDict = (COSDictionary) stream.getCOSObject(); + if (!streamDict.containsKey(COSName.N)) + { + addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, + "/N entry of ICC profile is mandatory")); + return false; + } + COSBase nValue = streamDict.getItem(COSName.N); + if (!(nValue instanceof COSNumber)) + { + addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, + "/N entry of ICC profile must be a number, but is " + nValue)); + return false; + } + int nNumberValue = ((COSNumber) nValue).intValue(); + if (nNumberValue != 1 && nNumberValue != 3 && nNumberValue != 4) + { + addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, + "/N entry of ICC profile must be 1, 3 or 4, but is " + nNumberValue)); + return false; + } + if (iccp.getNumComponents() != nNumberValue) + { + addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, + "/N entry of ICC profile is " + nNumberValue + " but the ICC profile has " + iccp.getNumComponents() + " components")); + return false; + } + return true; + } }