Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3544

Invalid ByteRange for getContents() method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0.3
    • Fix Version/s: None
    • Component/s: Signing
    • Labels:
      None

      Description

      PDSignature.java class, getContents() method, line 325ff.

      PDSignature.java
          /**
           * 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}));
          }
      

      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 (page 5) this is invalid:

      "In this example, the hash is calculated for bytes 0 through 839, and 960 through 1200."

      Thus the values for the signature should be

      {840, 119}

      which is from 840 - 959

      The implementation should be:

      PDSignature.java
          /**
           * 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}));
          }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              TeeWeTee Lonzak
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: