From 267e29e6c569c296faf58d9528eb913bfb68f511 Mon Sep 17 00:00:00 2001 From: Keichi Takahashi Date: Thu, 15 Oct 2026 23:30:18 +0900 Subject: [PATCH] Parse entropy-coded data in jpg example The scan data following an SOS segment was parsed as another segment, which yielded a bogus marker and seeked past the end of the file. Read it into a buffer up to the next marker so that following segments, including EOI, are parsed correctly. --- example/jpg.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/example/jpg.ts b/example/jpg.ts index 010c4eb1..3389b5b2 100644 --- a/example/jpg.ts +++ b/example/jpg.ts @@ -50,7 +50,12 @@ const SOS = Parser.start() }) .uint8("spectrumStart") .uint8("spectrumEnd") - .uint8("spectrumSelect"); + .uint8("spectrumSelect") + // Entropy-coded data continues until a marker other than 0xFF00 or RSTn + .buffer("data", { + readUntil: (b: number, buf: Buffer) => + b === 0xff && buf[1] !== 0 && (buf[1] < 0xd0 || buf[1] > 0xd7), + }); const DQT = Parser.start() .endianness("big")