fix(cam_hal): prevent SOI scan from (1) running on length<3 and (2) over-reading the last 2 bytes #760
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
First occurrence of each warning:
ESP_DRAM_LOGW() → zero stack after the first print.
Subsequent occurrences:
count with a uint16_t and emit a literal ESP_LOGW() only
every 100th event (~ 60 B stack usage).
Counters auto-reset at 10 000 to avoid wraparound.
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: