You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2016/10/27 07:53:59 UTC
[jira] [Closed] (PDFBOX-3544) Invalid ByteRange for getContents()
method
[ https://issues.apache.org/jira/browse/PDFBOX-3544?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tilman Hausherr closed PDFBOX-3544.
-----------------------------------
Resolution: Won't Fix
> Invalid ByteRange for getContents() method
> ------------------------------------------
>
> Key: PDFBOX-3544
> URL: https://issues.apache.org/jira/browse/PDFBOX-3544
> Project: PDFBox
> Issue Type: Bug
> Components: Signing
> Affects Versions: 2.0.3
> Reporter: Lonzak
>
> PDSignature.java class, getContents() method, line 325ff.
> {code:title=PDSignature.java|borderStyle=solid}
> /**
> * Will return the embedded signature between the byterange gap.
> *
> * @param pdfFile The signed pdf file as byte array
> * @return a byte array containing the signature
> * @throws IOException if the pdfFile can't be read
> */
> public byte[] getContents(byte[] pdfFile) throws IOException
> {
> int[] byteRange = getByteRange();
> int begin = byteRange[0]+byteRange[1]+1;
> int end = byteRange[2]-begin;
> return getContents(new COSFilterInputStream(pdfFile,new int[] {begin,end}));
> }
> {code:}
> Lets asume a byte range of
> /ByteRange[ 0, 840, 960, 240]
> The current implementation would return
> {841, 119} which is from *841 - 960*
> According to [adobe|http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/DigitalSignaturesInPDF.pdf] (page 5) this is invalid:
> {quote}
> "In this example, the hash is calculated for bytes 0 through 839, and 960 through 1200."
> {quote}
> Thus the values for the signature should be
> {840, 119} which is from *840 - 959*
> The implementation should be:
> {code:title=PDSignature.java|borderStyle=solid}
> /**
> * Will return the embedded signature between the byterange gap.
> *
> * @param pdfFile The signed pdf file as byte array
> * @return a byte array containing the signature
> * @throws IOException if the pdfFile can't be read
> */
> public byte[] getContents(byte[] pdfFile) throws IOException
> {
> int[] byteRange = getByteRange();
> int begin = byteRange[0]+byteRange[1];
> int end = byteRange[2]-begin-1;
> return getContents(new COSFilterInputStream(pdfFile,new int[] {begin,end}));
> }
> {code:}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org