Repository navigation
Commit 570df03
Validate TIFF tag values against libtiff's own field definition before TIFFSetField
PyImaging_LibTiffEncoderNew chose the TIFFSetField() argument shape
(scalar, tuple, or bytes) from the Python value alone, assuming its own
ImagingLibTiffMergeFieldInfo() registration would determine how libtiff
reads the varargs. It does not: TIFFMergeFieldInfo() never overrides
libtiff's built-in definition for a tag it already knows, so libtiff
reads the varargs according to its own field table regardless of what
Pillow pushed.
For a counted array tag such as DNGPrivateData (50740), a scalar
integer from the source file was taken by libtiff as a byte count, and
the data pointer was read from an argument slot Pillow never wrote --
copying that many bytes of process memory into the output tag. For a
fixed-size array tag such as ActiveArea (50829), the integer was used
directly as a source address, causing a segfault.
Add ImagingLibTiffFindField() to look up libtiff's actual field
definition (type, passcount, writecount) for a tag, and validate the
Python value against it before calling TIFFSetField, raising
ValueError instead of forwarding a mismatched value. The core tags that
have their own dedicated branches (ColorMap, YCbCrSubsampling,
ReferenceBlackWhite) are shape-checked too; ColorMap length is already
validated in Python. ReferenceBlackWhite no longer needs to be
blocklisted and is now written. TransferFunction remains unsupported by
the libtiff encoder and stays blocklisted, so it is still dropped.
Reported-by: carlini
Fixes: GHSA-xvh5-g6gv-559v
Co-authored-by: Copilot <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>1 parent 53318b5 commit 570df03
5 files changed
Lines changed: 314 additions & 32 deletions
File tree
- Tests
- src
- PIL
- libImaging
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
418 | 513 | | |
419 | 514 | | |
420 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1981 | 1981 | | |
1982 | 1982 | | |
1983 | 1983 | | |
1984 | | - | |
1985 | | - | |
1986 | | - | |
| 1984 | + | |
1987 | 1985 | | |
1988 | 1986 | | |
1989 | 1987 | | |
1990 | | - | |
1991 | 1988 | | |
1992 | 1989 | | |
1993 | 1990 | | |
| |||
0 commit comments