CVE-2025-59734
JSON

8.7high

Heap-buffer-overflow write in FFmpeg SANM process_ftch

Severity
8.7high CVSS:4.0 by Google
Exploit likelihood
0.18% (higher than 7% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
Google

Description

It is possible to cause an use-after-free write in SANM decoding with a carefully crafted animation using subversion <2. When a STOR chunk is present, a subsequent FOBJ chunk will be saved in ctx->stored_frame. Stored frames can later be referenced by FTCH chunks. For files using subversion < 2, the undecoded frame is stored, and decoded again when the FTCH chunks are parsed. However, in process_frame_obj if the frame has an invalid size, there’s an early return, with a value of 0.  This causes the code in decode_frame to still store the raw frame buffer into ctx->stored_frame. Leaving ctx->has_dimensions set to false. A subsequent chunk with type FTCH would call process_ftch and decode that frame obj again, adding to the top/left values and calling process_frame_obj again. Given that we never set ctx->have_dimensions before, this time we set the dimensions, calling init_buffers, which can reallocate the buffer in ctx->stored_frame, freeing the previous one. However, the GetByteContext object gb still holds a reference to the old buffer. Finally, when the code tries to decode the frame, codecs that accept a GetByteContext as a parameter will trigger a use-after-free read when using gb. GetByteContext is only used for reading bytes, so at most one could read invalid data. There are no heap allocations between the free and when the object is accessed. However, upon returning to process_ftch, the code restores the original values for top/left in stored_frame, writing 4 bytes to the freed data at offset 6, potentially corrupting the allocator’s metadata. This issue can be triggered just by probing whether a file has the sanm format. We recommend upgrading to version 8.0 or beyond.

Affected

Product or packageVersionsReported by
SANMfrom 4d7c609be37dc57d31527c8c9e5945dc9491a7cd before 8.0, from 7.1.1 before 8.0CVE List

Classification

CWE-416

SSVC (CISA-ADP): exploitation none, automatable no, technical impact total.

What each source says

CVE List

It is possible to cause an use-after-free write in SANM decoding with a carefully crafted animation using subversion <2. When a STOR chunk is present, a subsequent FOBJ chunk will be saved in ctx->stored_frame. Stored frames can later be referenced by FTCH chunks. For files using subversion < 2, the undecoded frame is stored, and decoded again when the FTCH chunks are parsed. However, in process_frame_obj if the frame has an invalid size, there’s an early return, with a value of 0.  This causes the code in decode_frame to still store the raw frame buffer into ctx->stored_frame. Leaving ctx->has_dimensions set to false. A subsequent chunk with type FTCH would call process_ftch and decode that frame obj again, adding to the top/left values and calling process_frame_obj again. Given that we never set ctx->have_dimensions before, this time we set the dimensions, calling init_buffers, which can reallocate the buffer in ctx->stored_frame, freeing the previous one. However, the GetByteContext object gb still holds a reference to the old buffer. Finally, when the code tries to decode the frame, codecs that accept a GetByteContext as a parameter will trigger a use-after-free read when using gb. GetByteContext is only used for reading bytes, so at most one could read invalid data. There are no heap allocations between the free and when the object is accessed. However, upon returning to process_ftch, the code restores the original values for top/left in stored_frame, writing 4 bytes to the freed data at offset 6, potentially corrupting the allocator’s metadata. This issue can be triggered just by probing whether a file has the sanm format. We recommend upgrading to version 8.0 or beyond.

NVD (es)

Es posible causar una escritura de uso después de liberación en la decodificación SANM con una animación cuidadosamente diseñada usando subversión <2. Cuando un chunk STOR está presente, un chunk FOBJ subsiguiente se guardará en ctx -> stored_frame. Los frames almacenados pueden ser referenciados más tarde por chunks FTCH. Para archivos que usan subversión < 2, el frame sin decodificar se almacena y se decodifica de nuevo cuando se analizan los chunks FTCH. Sin embargo, en process_frame_obj, si el frame tiene un tamaño inválido, hay un retorno anticipado, con un valor de 0. Esto provoca que el código en decode_frame siga almacenando el búfer de frame en bruto en ctx -> stored_frame. Dejando ctx -> has_dimensions establecido en falso. Un chunk subsiguiente de tipo FTCH llamaría a process_ftch y decodificaría ese objeto de frame de nuevo, añadiendo a los valores superior/izquierdo y llamando a process_frame_obj de nuevo. Dado que nunca establecimos ctx -> have_dimensions antes, esta vez establecemos las dimensiones, llamando a init_buffers, lo que puede reasignar el búfer en ctx -> stored_frame, liberando el anterior. Sin embargo, el objeto GetByteContext gb todavía mantiene una referencia al búfer antiguo. Finalmente, cuando el código intenta decodificar el frame, los códecs que aceptan un GetByteContext como parámetro activarán una lectura de uso después de liberación al usar gb. GetByteContext solo se usa para leer bytes, por lo que, como máximo, se podrían leer datos inválidos. No hay asignaciones de heap entre la liberación y el momento en que se accede al objeto. Sin embargo, al regresar a process_ftch, el código restaura los valores originales para superior/izquierdo en stored_frame, escribiendo 4 bytes en los datos liberados en el desplazamiento 6, potencialmente corrompiendo los metadatos del asignador. Este problema puede ser activado simplemente al sondear si un archivo tiene el formato sanm. Recomendamos actualizar a la versión 8.0 o posterior.

References

Sources

SourceRecordLicence
CVE ListCVE-2025-59734 changed 2026-02-26CVE Terms of Use
NVDCVE-2025-59734 changed 2026-10-19Public domain