Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem getting geometry of pre-signed URLs containing X-Amz-Security-Token #138

Open
xinspire opened this issue May 16, 2024 · 0 comments

Comments

@xinspire
Copy link

xinspire commented May 16, 2024

Describe the bug
Apologies in advance if this is not the right place to put it. After spending hours tracking down this bug, it seems to be a combination of multiple things, but the simplest solution I think is to update kt-paperclip.

When using temporary credentials, AWS generates pre-signed URLs that include a very long X-Amz-Security-Token, bringing the total length of the URL to greater than an implicit character limit that ImageMagick's identify seem to have. In our particular case, the limit was about 1030 characters. Any call to identify <URL> where URL is greater than this LIMIT would cause identify to throw the error "identify: unable to create temporary file", which causes everything that relies on it (including calls from kt-paperclip's Geometry#from_file) to fail.

To Reproduce
Steps to reproduce the behavior using just the command line:

  1. Install Amazon Linux 2023 (6.1.79-99.164.amzn2023.aarch64)
  2. Install ImageMagick (I'm using the latest 7.1.1-32)
  3. Run in bash: identify "<URL>" where <URL> is a really long URL. A simple example is below:
    identify "https://www.google.com/logos/doodles/2024/celebrating-hank-adams-6753651837110220-s.png?test=" worked
    identify "https://www.google.com/logos/doodles/2024/celebrating-hank-adams-6753651837110220-s.png?test=<insert 800 spaces>" worked
    identify "https://www.google.com/logos/doodles/2024/celebrating-hank-adams-6753651837110220-s.png?test=<insert 1100 spaces>" did not work
  4. See error "identify: unable to create temporary file"

Expected behavior
It should not have an error, but return some info about the file at the URL, including its format and size.

Additional context
I suspect the problem is in identify's way of handling arguments, but I haven't dug into the ImageMagick source. Since so many people run different versions of ImageMagick, it may be easier to solve this problem by updating kt-paperclip. Specifically, in Geometry#from_file, one can write the contents of the remote file to a Tempfile, and then pass the Tempfile to GeometryDetector rather than passing in the URL directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant