Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Potential signed-to-unsigned conversion in TIFF dimension parsing

Aperta Adatta ai principianti
#24,196 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, php
Ambito
backend

Direzione di ricerca

Inizia in ext/standard/image.c, in php_handle_tiff(), soprattutto nella gestione di TAG_FMT_SSHORT e nelle assegnazioni di IMAGEWIDTH/IMAGEHEIGHT individuate nell’issue. Verifica come vengono convalidati i tipi dei campi delle dimensioni TIFF ed esegui i test pertinenti per immagini/TIFF. Il lavoro è completato quando i valori negativi con segno non possono diventare dimensioni, mentre le dimensioni valide di tipo SHORT o LONG senza segno continuano a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Status: Needs Triage
Description

Hi, It seemed to me that a negative signed value could potentially be converted to a large unsigned value here.

A potential signed-to-unsigned conversion issue exists in php_handle_tiff() when processing TIFF image dimensions.

The entry_value variable is declared as size_t, while the TAG_FMT_SSHORT case assigns the return value of php_ifd_get16s() to it:

case TAG_FMT_SSHORT:
entry_value = php_ifd_get16s(dir_entry+8, motorola_intel);
break;

php_ifd_get16s() returns a signed 16-bit value. Therefore, a negative value from the TIFF input can be converted to a large unsigned size_t value.

If such an entry is subsequently identified as TAG_IMAGEWIDTH or TAG_IMAGEHEIGHT, the converted value is assigned to width or height:

case TAG_IMAGEWIDTH:
case TAG_COMP_IMAGEWIDTH:
width = entry_value;
break;

case TAG_IMAGEHEIGHT:
case TAG_COMP_IMAGEHEIGHT:
height = entry_value;
break;

For example, a signed value of -1 can be converted to the maximum value of size_t instead of remaining negative.

According to the TIFF 6.0 specification, ImageWidth and ImageLength use the SHORT or LONG types, where SHORT is an unsigned 16-bit integer. The reader is expected to validate the field type.

Impact

A malformed TIFF containing a negative SSHORT value for an image dimension can therefore cause the parser to produce an unexpectedly large width or height.

Proposed solution

Validate the signed value before assigning it to the unsigned entry_value variable and reject negative values.

PHP Version
PHP 8.3.31 (CLI)
Operating System

Ubuntu 24.04

Lingua principale
C
Stelle
40.4k
Fork
8.2k
Merge medio
2g 59m
PR unite (30g)
155

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di php/php-src

Tutte le issue di php/php-src

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.