python / python/cpython

Guard against negative offset/length values in tarfile's GNU sparse extraction

Abierto
#137,396 11 comentarios 0 reacciones 2 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:
for i in range(21):
    try:
        offset = nti(buf[pos:pos + 12])
        numbytes = nti(buf[pos + 12:pos + 24])
    except ValueError:
        break
    if offset and numbytes:
        structs.append((offset, numbytes))
    pos += 24

https://github.com/python/cpython/blob/7040aa54f14676938970e10c5f74ea93cd56aa38/Lib/tarfile.py#L1441

  • There is no check that offset or numbytes are non-negative.
  • The check if offset and numbytes: only skips zero, not negative numbers.
validation should be added:
if offset >= 0 and numbytes >= 0:
    structs.append((offset, numbytes))
  • This will prevent the addition of invalid sparse mappings, mitigating the risk.
CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs
  • gh-137805
  • gh-138726

Guía de contribución

Abrir la guía de contribución

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.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.