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

Screenshot and thumbnail not created in the same directory #226

Open
guijan opened this issue Mar 17, 2023 · 1 comment
Open

Screenshot and thumbnail not created in the same directory #226

guijan opened this issue Mar 17, 2023 · 1 comment

Comments

@guijan
Copy link
Contributor

guijan commented Mar 17, 2023

Consider the following invocation:

scrot --thumb 10 /tmp/test.png

Scrot's execution would then be like this:

First, we'd end up on this line:

imlib_save_image_with_error_return(filenameIM, &imErr);

The string filenameIM points to would be "/tmp/test.png"

A little further down, we'd end up on this line of code:

imlib_save_image_with_error_return(filenameThumb, &imErr);

The string filenameThumb points to would be "/tmp/test-thumb.png"

The bug here is that between those 2 lines of code, /tmp/ could be changed to point to a different directory.

The solution should be to chdir() to the output file's directory, then handle the output file and thumbnail file as basenames only.
This also has the nice side effect of allowing the creation of output files with longer filenames: as the code currently stands, with a PATH_MAX of 4096 as is typical these days, if the directory portion of the filename alone is 4000 bytes, we may be unable to create a file with a basename over 95 bytes (+ 1 byte reserved for the '\0') even though X/Open guarantees NAME_MAX is at least 255.

@N-R-K
Copy link
Collaborator

N-R-K commented May 24, 2024

I just realized that the scrotCheckIfOverwriteFile thing also applies to the thumbnail.

So if user does scrot -t16 shot.png and shot.png didn't exist but shot-thumb.png did, then it'll write the thumbnail to shot-thumb_000.png instead.

I suppose that "works", but I'm not sure if that's intuitive or not. At the very least, we should probably document the behavior.

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

No branches or pull requests

2 participants