Menu

#62 Fix for GetImageClippingPathAttribute

Unstable_(example)
closed-fixed
None
5
2023-07-01
2019-10-30
No

GetImageClippingPathAttribute returns any path present in the Image Resouce Blocks. This patch changes it to check for the presence of the clipping path name (ID=2999). If that's found, it searches for a path with that name. Otherwise, it returns NULL.

1 Attachments

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2019-11-25
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2019-11-25

    How was the allocation size of attr_name selected? Is there a specification which provides the maximum length of a clipping path name (the value part)?

    As written, the patch is a recipie for a stack overwrite or reading outside the bounds of a heap allocation if the input is intentionally corrupted.

    I am able to make it robust but am curious about the clipping path name length.

     
    • Phillip Seaver

      Phillip Seaver - 2019-11-25

      The name in the Image Resource Block is a Pascal string, so it's limited to 255. The beginning of the query string is 15 characters. Add a trailing null and 271 is the max. (I made it larger than I needed to in case I needed to add more to the beginning, if I recall correctly. Just being a little paranoid)

      Here's the Adobe specification about Image Resource Blocks: https://www.adobe.com/content/dam/acom/en/devnet/photoshop/psir/ps_image_resources.pdf

       
      • Bob Friesenhahn

        Bob Friesenhahn - 2019-11-25

        On Mon, 25 Nov 2019, Phillip Seaver wrote:

        The name in the Image Resource Block is a Pascal string, so it's
        limited to 255. The beginning of the query string is 15 characters.
        Add a trailing null and 271 is the max. (I made it larger than I
        needed to in case I needed to add more to the beginning, if I recall
        correctly. Just being a little paranoid)

        As a reminder, a corrupted or non-conforming file could produce any
        input. The input could be too short or too long. Null termination
        may be missing. More paranoia is required. I have updated my copy
        with more paranoia but perhaps not enough yet.

        Here's the Adobe specification about Image Resource Blocks:
        https://www.adobe.com/content/dam/acom/en/devnet/photoshop/psir/ps_image_resources.pdf

        I will take a look.

        Bob

        Bob Friesenhahn
        bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
        GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
        Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

         
      • Bob Friesenhahn

        Bob Friesenhahn - 2019-11-26

        On Mon, 25 Nov 2019, Phillip Seaver wrote:

        The name in the Image Resource Block is a Pascal string, so it's limited to 255. The beginning of the query string is 15 characters. Add a trailing null and 271 is the max. (I made it larger than I needed to in case I needed to add more to the beginning, if I recall correctly. Just being a little paranoid)

        Here's the Adobe specification about Image Resource Blocks: https://www.adobe.com/content/dam/acom/en/devnet/photoshop/psir/ps_image_resources.pdf

        I did not see a description of a "Pascal string" in Adobe's document.
        The only description I see of a string in the document is a string
        comprised of 16-bit Unicode characters with a preceding 4-byte size
        field. A string like this could be larger than 255.

        Are you able to provide a sample file that I can use for testing?

        Bob

        Bob Friesenhahn
        bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
        GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
        Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

         
        • Bob Friesenhahn

          Bob Friesenhahn - 2019-11-26

          On Tue, 26 Nov 2019, Bob Friesenhahn wrote:

          Are you able to provide a sample file that I can use for testing?

          If you do provide a sample file, make sure to wrap it in a zip file or
          some other archive format which will prevent SourceForge from
          re-writing it.

          Bob

          Bob Friesenhahn
          bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
          GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
          Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt

           
          • Phillip Seaver

            Phillip Seaver - 2019-11-26

            I'll have to check with the customer. It was generated by Photoshop, but I don't use it, so I can't tell you the steps. I'll see if I can find out.

             
        • Phillip Seaver

          Phillip Seaver - 2019-11-26

          Interestingly, I found it used in a few Adobe specs without being defined. It's a one-byte length followed by the string, instead of being null-terminated. https://en.wikipedia.org/wiki/String_(computer_science)#Length-prefixed

           
  • Bob Friesenhahn

    Bob Friesenhahn - 2019-12-06

    A one-byte length does not seem very useful. A variable size length indication (e.g. based on the top bit being set) seems more useful. It seems that we need to learn more about this.

    Regardless, I am attaching an alternate patch. Please take a look at it and see if it works for you. I don't plan on committing any fix until I have a test case and have had the time to fully analyze the issue.

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2019-12-06

    Alternative patch

     
  • Bob Friesenhahn

    Bob Friesenhahn - 2023-07-01
    • status: open --> closed-fixed
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2023-07-01

    Something similar to this is committed as Mercurial Changeset 17119:d09ea9c70be7. Hopefully all is OK!

     

Log in to post a comment.