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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not fail to send images with wrong extensions #5299

Merged
merged 1 commit into from
Jun 3, 2024

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Feb 29, 2024

No description provided.

src/chat.rs Outdated Show resolved Hide resolved
@link2xt link2xt force-pushed the main branch 2 times, most recently from 1abb12e to 2af9ff1 Compare March 4, 2024 21:10
@iequidoo iequidoo self-assigned this May 31, 2024
Try to guess the image format based on its content first.

Co-authored-by: iequidoo <dgreshilov@gmail.com>
@iequidoo iequidoo requested a review from r10s June 2, 2024 20:34
@iequidoo iequidoo changed the title fix: do not fail to send JPEG with .png extension fix: Do not fail to send images with wrong extensions Jun 2, 2024
*no_exif_ref = exif.is_none();
let mut img = image::open(&blob_abs).context("image decode failure")?;
// It's strange that BufReader modifies a file position while it takes a non-mut
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewinding file descriptor does not require a mutable reference. Or it's internal mutability (i.e. reader/file takes care of the locks). In any case, if it compiles then it's fine, better remove this comment.

Copy link
Collaborator

@iequidoo iequidoo Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove mut from the file declaration:

435 |             file.rewind()?;
    |             ---- cannot borrow as mutable

So it's not internal mutability (if i understand it correctly). EDIT: and it doesn't work w/o these rewinds

@iequidoo
Copy link
Collaborator

iequidoo commented Jun 3, 2024

@link2xt you can't approve this being the author, so please just merge this if it looks good to you

@link2xt link2xt merged commit 3040505 into main Jun 3, 2024
31 of 37 checks passed
@link2xt link2xt deleted the link2xt/send-jpeg-as-png branch June 3, 2024 14:56
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

Successfully merging this pull request may close these issues.

None yet

3 participants