Skip to content

Conversation

@RubenKelevra
Copy link
Contributor

@RubenKelevra RubenKelevra commented Jul 1, 2025

x## Description

Changes:

  • Store SOI as a 3-byte array (0xFF D8 FF) and use sizeof() everywhere.
  • Early-exit when length < 3 to avoid over-reading
  • calculate end index correctly, to avoid over-reading

Related

In the search for the cause of crashes reported by @turenkomv here: esphome/esphome#8832 (comment) I found this overread of a pointer, which can cause undefined behaviour.

Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass. (?)
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@RubenKelevra
Copy link
Contributor Author

@turenkomv thanks for your patience. Sadly this bug can IMHO not cause a stack trashing, only cause wrong returns.

@RubenKelevra
Copy link
Contributor Author

Log changes moved to PR #765 to keep this PR small.

@RubenKelevra RubenKelevra force-pushed the fix_jpeg-soi-overread branch from 711b572 to 21dfb11 Compare July 10, 2025 17:01
@RubenKelevra
Copy link
Contributor Author

Updated to the latest master branch commit

@me-no-dev
Copy link
Member

I will merge this next, but first update the branch and do not use sizeof for SOI and EOI. Your other PR will go after that with everything from the previous and this one merged it.

              and (2) over-reading the last 2 bytes

Changes:
* Store SOI as a 3-byte array (0xFF D8 FF)
* Early-exit when length < 3 to avoid over-reading
* calculate end index correctly, to avoid over-reading
@RubenKelevra RubenKelevra force-pushed the fix_jpeg-soi-overread branch from 21dfb11 to 3e50b59 Compare July 14, 2025 10:56
@RubenKelevra RubenKelevra marked this pull request as ready for review July 14, 2025 10:59
@RubenKelevra
Copy link
Contributor Author

but first update the branch and do not use sizeof for SOI and EOI.

Thanks for the suggestion, I've changed this.

Should be ready for merge now. :)

@me-no-dev me-no-dev merged commit cbed97c into espressif:master Jul 14, 2025
30 checks passed
@RubenKelevra RubenKelevra deleted the fix_jpeg-soi-overread branch July 15, 2025 19:46
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.

2 participants