Skip to content

image/jpeg: misleading comment on maximum t value on receiveExtend() #81128

Open

Description

@dlecorfec

In current git repo (go1.27), the comment on huffman.go:receiveExtend() is the following:

// receiveExtend is the composition of RECEIVE and EXTEND, specified in section
// F.2.2.1.
//
// It returns the signed integer that's encoded in t bits, where t < 16. The
// possible return values are:
//
// - t == 0: 0
// - t == 1: -1, +1
// - t == 2: -3, -2, +2, +3
// - t == 3: -7, -6, -5, -4, +4, +5, +6, +7
// - ...
// - t == 15: -32767, -32766, ..., -16384, +16384, ..., +32766, +32767

But in scan.go:249, the DC path only rejects value > 16, so value == 16 is explicitly allowed.
That value is passed directly to receiveExtend in scan.go:251.

So the comment should indicate t <= 16 instead, and add

// - t == 16: -65535, -65534, ..., -32768, +32768, ..., +65534, +65535

(disclaimer: AI-found, Gemini and GPT seem to agree on t == 16 being allowed in the JPEG specs)

Activity

  1. changed the title [-]image/jpeg: misleading comment on receiveExtend[/-] [+]image/jpeg: misleading comment on maximum t value on receiveExtend()[/+] on Aug 26, 2026
  2. prattmic commented on Sep 4, 2026

    @prattmic
    Member
  3. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 4, 2026
  4. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846305 mentions this issue: image/jpeg: reject DC difference category 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions