Skip to content

fix getJpegInfo to skip DHT marker #3854

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rnigro-rwb
Copy link

Fixes #3318.

getJpegInfo now skips the DHT marker (0xc4) because that marker is not a SOF (start of frame) marker and therefore the segment to follow does not have the size information.

To add to insight to this fix, the original getJpegInfo sites http://www.64lines.com/jpeg-width-height which itself sites a reference for header info: JPEG Header Information

As you can see here, Define Huffman table marker (FFC4), 0xC4 is a marker for the Huffman table.

My fix skips 0xC4 and adjusts the remaining Start of frame (SOFn) markers to be correct.

@rnigro-rwb rnigro-rwb marked this pull request as ready for review April 3, 2025 14:39
@mbrittsess
Copy link

So, what needs to be done to get those pending checks to actually run?

@MrRio
Copy link
Member

MrRio commented Jun 20, 2025

Let me have a look into this

@MrRio MrRio requested a review from Copilot June 28, 2025 02:14
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates getJpegInfo to properly skip the DHT marker (0xC4) since it is not a Start Of Frame marker.

  • Refines comment block to label SOF markers and note skipping of DHT
  • Removes 0xc4 from the markers array
  • Adjusts the list of subsequent SOF markers
Comments suppressed due to low confidence (3)

src/modules/jpeg_support.js:29

  • [nitpick] Consider renaming markers to sofMarkers or SOF_MARKERS to more clearly convey that this array contains Start Of Frame markers.
  var markers = [0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7];

src/modules/jpeg_support.js:24

  • Add a unit test that includes a JPEG with a DHT segment to verify that getJpegInfo correctly skips the DHT marker and still extracts width and height.
   * 0xc4 Define Huffman Tables (DHT) - skip

src/modules/jpeg_support.js:29

  • Use const instead of var for the markers array since it is not reassigned.
  var markers = [0xc0, 0xc1, 0xc2, 0xc3, 0xc5, 0xc6, 0xc7];

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.

jsPDF images are corrupted when using large, smartphone-captured jpegs
3 participants