Skip to content

docs(readme): harden jpg_stream_httpd_handler example & fix bugs #773

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

Conversation

RubenKelevra
Copy link
Contributor

Description

Changes:

  • Use %zu in _STREAM_PART for size_t-safe Content-Length formatting.
  • Fix part_buf type: char part_buf[64] (was array of char pointers).
  • initialize local JPEG buffer vars: jpg_buf_len/jpg_buf
    • drop leading underscores on them for consistency with other locals
  • Bound snprintf() by sizeof(part_buf); capture int hlen.
  • Detect and log header truncation with required/available sizes; fail gracefully.
  • Break out of loop on JPEG compression failure to avoid invalid buffer use.
  • Send header chunk only when formatting succeeds.
  • Guard FPS calculation against divide-by-zero; compute once as fps.
  • Remove unsafe/needless pointer cast.
  • Minor style cleanups for readability.

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.

Changes:
* Use `%zu` in _STREAM_PART for size_t-safe Content-Length formatting.
* Fix `part_buf` type: `char part_buf[64]` (was array of char pointers).
* initialize local JPEG buffer vars: `jpg_buf_len`/`jpg_buf`
  * drop leading underscores on them for consistency with other locals
* Bound `snprintf()` by `sizeof(part_buf)`; capture `int hlen`.
* Detect and log header truncation with required/available sizes; fail gracefully.
* Break out of loop on JPEG compression failure to avoid invalid buffer use.
* Send header chunk only when formatting succeeds.
* Guard FPS calculation against divide-by-zero; compute once as `fps`.
* Remove unsafe/needless pointer cast.
* Minor style cleanups for readability.
@RubenKelevra RubenKelevra force-pushed the docs/fix-jpg-stream-example-buffer-and-size-handling branch from 7f1f0d4 to 7673d3e Compare July 17, 2025 17:56
@me-no-dev me-no-dev merged commit 3ca876a into espressif:master Jul 18, 2025
30 checks passed
@RubenKelevra RubenKelevra deleted the docs/fix-jpg-stream-example-buffer-and-size-handling branch July 18, 2025 13:09
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