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

Abierto Apto para principiantes
#2,440 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@Aditya-Saroha ya está trabajando en esto.

Desde el 1/11/2026.

  • #2441 de @Aditya-Saroha — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c
Área
security

Línea de trabajo

Empieza en dvbsub_parse_clut_segment() en src/lib_ccx/dvb_subtitle_decoder.c, donde entry_id indexa los arrays clut4, ilut4, clut16 e ilut16 de DVBSubCLUT sin comprobación de rango. Lee la definición de la estructura DVBSubCLUT para confirmar los tamaños de los arrays. Se considera terminado cuando cada rama de 2 bits y de 4 bits rechaza un entry_id fuera de rango antes de escribir, y un segmento CLUT manipulado ya no corrompe la memoria. Como se trata de un informe de seguridad, consulta con los mantenedores cómo deben gestionarse la corrección y cualquier prueba.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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;
             }
Lenguaje dominante
C
Estrellas
912
Forks
598
Merge medio
1 d 23 h
PR fusionados (30 d)
25

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CCExtractor/ccextractor

Todos los issues de CCExtractor/ccextractor

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.