[BUG] DVB subtitle decoder: heap-buffer-overflow write in dvbsub_parse_clut_segment via unbounded entry_id

Aperta Adatta ai principianti
#2,440 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@Aditya-Saroha ci sta già lavorando.

Dal 1/11/2026.

  • #2441 di @Aditya-Saroha — aperta

Valutazione

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

Direzione di ricerca

Inizia da dvbsub_parse_clut_segment() in src/lib_ccx/dvb_subtitle_decoder.c, dove entry_id indicizza gli array clut4, ilut4, clut16 e ilut16 di DVBSubCLUT senza un controllo dell'intervallo. Leggi la definizione della struct DVBSubCLUT per confermare la dimensione degli array. Il lavoro è completato quando ogni ramo a 2 bit e a 4 bit rifiuta un entry_id fuori intervallo prima di scrivere, e un segmento CLUT costruito ad arte non corrompe più la memoria. Trattandosi di una segnalazione di sicurezza, chiedi ai maintainer come gestire la correzione e l'eventuale test.

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

Descrizione

Summary

In src/lib_ccx/dvb_subtitle_decoder.c, dvbsub_parse_clut_segment() writes palette entries into fixed-size arrays (clut4, ilut4, clut16, ilut16) using the stream-supplied entry_id byte without verifying that entry_id fits within the array bounds.

When a DVB subtitle stream declares 2-bit depth (depth & 0x80) or 4-bit depth (depth & 0x40), an entry_id >= 4 or entry_id >= 16 causes an out-of-bounds write on the heap, corrupting adjacent members of DVBSubCLUT including the clut->next heap linked-list pointer.


Vulnerability Details
  • Affected file: src/lib_ccx/dvb_subtitle_decoder.c
  • Function: dvbsub_parse_clut_segment()
  • CWE: CWE-787: Out-of-bounds Write (Heap-based Buffer Overflow)

DVBSubCLUT is defined as:

typedef struct DVBSubCLUT
{
    int id;
    int version;

    uint32_t clut4[4];    // 2-bit palette: 4 entries (indices 0..3)
    uint32_t clut16[16];  // 4-bit palette: 16 entries (indices 0..15)
    uint32_t clut256[256];
    uint8_t ilut4[4];     // 2-bit luma: 4 entries (indices 0..3)
    uint8_t ilut16[16];   // 4-bit luma: 16 entries (indices 0..15)
    uint8_t ilut256[256];

    struct DVBSubCLUT *next; // heap linked-list pointer
} DVBSubCLUT;

In dvbsub_parse_clut_segment():

while (buf + 4 < buf_end)
{
    entry_id = *buf++; // stream-supplied byte (0..255)
    depth = (*buf) & 0xe0;
    ...
    if (depth & 0x80) // 2-bit CLUT
    {
        clut->clut4[entry_id] = RGBA(r, g, b, 255 - alpha); // OOB write if entry_id >= 4                                                                                               
        clut->ilut4[entry_id] = y;                          // OOB write if entry_id >= 4                                                                                               
    }
    else if (depth & 0x40) // 4-bit CLUT
    {
        clut->clut16[entry_id] = RGBA(r, g, b, 255 - alpha); // OOB write if entry_id >= 16                                                                                             
        clut->ilut16[entry_id] = y;                           // OOB write if entry_id >= 16                                                                                            
    }
    else if (depth & 0x20)
    {
        clut->clut256[entry_id] = RGBA(r, g, b, 255 - alpha);                                                                                                                           
        clut->ilut256[entry_id] = y;                                                                                                                                                    
    }
}
  1. 2-bit CLUT (depth & 0x80): clut4 and ilut4 have only 4 elements. If entry_id is between 4 and 255, clut->clut4[entry_id] writes past the allocated space.
  2. 4-bit CLUT (depth & 0x40): clut16 and ilut16 have only 16 elements. If entry_id is between 16 and 255, clut->clut16[entry_id] writes past the allocated space.
  3. In both cases, the out-of-bounds write overwrites the heap next pointer (clut->next), leading to crashes or memory corruption during subsequent list traversal or cleanup in dvbsub_free().

Reachability

In standard MPEG transport streams with DVB subtitles (stream type 0x06 and DVB subtitling descriptor 0x59), PES packets carrying subtitle segment type 0x12 (DVB_SUB_SEGMENT_CLUT) are decoded by dvbsub_decode() in src/lib_ccx/dvb_subtitle_decoder.c, reaching dvbsub_parse_clut_segment() on the default configuration.


Suggested Fix

Add bounds validation for entry_id against the palette capacity for both 2-bit and 4-bit entries:

--- a/src/lib_ccx/dvb_subtitle_decoder.c
+++ b/src/lib_ccx/dvb_subtitle_decoder.c
@@ -1216,11 +1216,21 @@ static int dvbsub_parse_clut_segment(void *dvb_ctx, const uint8_t *buf,
             if (depth & 0x80)
             {
+                if (entry_id >= 4)
+                {
+                    mprint("dvbsub_parse_clut_segment(): entry_id %d exceeds 2-bit CLUT bounds\n", entry_id);
+                    return -1;
+                }
                 clut->clut4[entry_id] = RGBA(r, g, b, 255 - alpha);
                 clut->ilut4[entry_id] = y;
             }
             else if (depth & 0x40)
             {
+                if (entry_id >= 16)
+                {
+                    mprint("dvbsub_parse_clut_segment(): entry_id %d exceeds 4-bit CLUT bounds\n", entry_id);
+                    return -1;
+                }
                 clut->clut16[entry_id] = RGBA(r, g, b, 255 - alpha);
                 clut->ilut16[entry_id] = y;
             }
Lingua principale
C
Stelle
912
Fork
598
Merge medio
1g 23h
PR unite (30g)
25

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 CCExtractor/ccextractor

Tutte le issue di CCExtractor/ccextractor

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.