Repository navigation
Commit 03bb80c
fix: decode the last sample of a scan that ends on a byte boundary
An entropy coded segment whose final Huffman code lands exactly on a byte
boundary needs no padding bits (T.81 B.1.1.2 pads only an incomplete final
byte), so EOI follows the last code immediately. `getHuffmanValue` and `getn`
treated that as having read into the marker and abandoned the scan one sample
early, leaving the frame's last sample 0.
`temp` holds `index` unconsumed bits. Once the 0xFF that introduces a marker
has been shifted in, its 8 bits are not data, so `index - 8` real bits are
left and consuming the last of them leaves `index === 8` - still a valid
decode. The guards tested `index < markerIndex` (9), which rejects it.
`readPastEntropyData` puts the boundary at `index < 8` and names what it is
testing; `markerIndex` keeps its 9 purely as the "marker seen" sentinel that
the other call sites already treat it as.
This replaces the `!isLastPixel()` special case in `getn`, which was covering
the same off-by-one for one of the three guard sites.
Reproduced with the single fragment of
CTImage.dcm_JPEGProcess14SV1TransferSyntax_1.2.840.10008.1.2.4.70.dcm, written
by DCMTK 3.6.1: 512x512 16 bit signed, ending in a long run of the image
minimum whose two-bit zero-difference codes tile the final byte exactly. Its
last sample decoded as 0 instead of -2000; every other sample was already
correct. Added as tests/data/jpeg_lossless_sel1-byte-aligned-end.jpg, checked
against the crc32 of the uncompressed CTImage.dcm pixel data.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent ea0eaa0 commit 03bb80c
3 files changed
Lines changed: 98 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
| |||
505 | 514 | | |
506 | 515 | | |
507 | 516 | | |
508 | | - | |
| 517 | + | |
509 | 518 | | |
510 | 519 | | |
511 | 520 | | |
| |||
528 | 537 | | |
529 | 538 | | |
530 | 539 | | |
531 | | - | |
| 540 | + | |
532 | 541 | | |
533 | 542 | | |
534 | 543 | | |
| |||
543 | 552 | | |
544 | 553 | | |
545 | 554 | | |
546 | | - | |
| 555 | + | |
547 | 556 | | |
548 | 557 | | |
549 | 558 | | |
| |||
575 | 584 | | |
576 | 585 | | |
577 | 586 | | |
578 | | - | |
579 | | - | |
| 587 | + | |
580 | 588 | | |
581 | 589 | | |
582 | 590 | | |
| |||
590 | 598 | | |
591 | 599 | | |
592 | 600 | | |
593 | | - | |
| 601 | + | |
594 | 602 | | |
595 | 603 | | |
596 | 604 | | |
| |||
609 | 617 | | |
610 | 618 | | |
611 | 619 | | |
612 | | - | |
| 620 | + | |
613 | 621 | | |
614 | 622 | | |
615 | 623 | | |
| |||
621 | 629 | | |
622 | 630 | | |
623 | 631 | | |
624 | | - | |
| 632 | + | |
625 | 633 | | |
626 | 634 | | |
627 | 635 | | |
| |||
669 | 677 | | |
670 | 678 | | |
671 | 679 | | |
672 | | - | |
673 | | - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
674 | 700 | | |
675 | 701 | | |
676 | 702 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
Loading
0 commit comments