Skip to content

Refactor JPEG size retrieval function - #25226

Merged
Jason2866 merged 3 commits into
arendst:developmentfrom
Jason2866:support_jpeg
Nov 5, 2026
Merged

Jason2866 merged 3 commits into
arendst:developmentfrom
Jason2866:support_jpeg

Conversation

@Jason2866

Copy link
Copy Markdown
Collaborator

Description:

Refactor get_jpeg_size function to improve JPEG parsing and validation.

  • Bug Fixes
    • Improved JPEG image handling so valid baseline images can be recognized without JFIF metadata, and their dimensions are extracted more reliably.
    • Invalid or incomplete JPEG data and progressive JPEG images are rejected.

Related (if applicable): #25219 @SHIFox8

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.8
  • The code change is tested and works with Tasmota core ESP32 V.3.3.12-1 from Platform 2026.10.50
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

Refactor get_jpeg_size function to improve JPEG parsing and validation.
@Jason2866

Copy link
Copy Markdown
Collaborator Author

@arendst Should be good to be merged. Tested with several jpeg files.

@s-hadinger

Copy link
Copy Markdown
Collaborator

I submitted an AI review, and it proposed some improvements:

  • Outputs stay set when the function returns false, however the callers don't test for return value. Fix: store the SOF0 values in locals and assign them only on return true.
  • The USE_BERRY_IMAGE guard adds code nothing calls. xdrv_52_3_berry_img.ino uses its own be_img_util::jpeg_size()
  • Requiring EOI is not stricly required if we accept to decode partially truncated files. Returning true at SOF0 or
    at the first SOS would cut about 25 lines and leave truncation to the decoder.

Do you want me to update the files in place in this PR?

@Jason2866

Jason2866 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator Author

@s-hadinger i added the USE_BERRY_IMAGE since the jpeg size refactor is part of implementation of a new epd display.
The jpeg_size in xdrv_52_3_berry_img.ino is redundant code which can be removed and can call the function here.

Not complete jpeg is an error and should not be accepted.

@s-hadinger

Copy link
Copy Markdown
Collaborator

Ok, let me fix that

@s-hadinger

Copy link
Copy Markdown
Collaborator

Wait, let me clean up my mess

@s-hadinger

Copy link
Copy Markdown
Collaborator

Ok, I just limited to zeroing the height/width when the JPEG is rejected.
Overall it's not ideal to use unsigned short types, it would be more explicit to use uint16_t instead.

@Jason2866
Jason2866 merged commit 760d69b into arendst:development Nov 5, 2026
16 of 66 checks passed
@Jason2866
Jason2866 deleted the support_jpeg branch November 5, 2026 14:24
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