[vector_graphics_compiler]: Fix Stack Overflow and CPU/Memory DoS on SVGs with circular references or exponential expansions#11740
Conversation
43561af to
8104b02
Compare
5076bbc to
936bd4f
Compare
|
The code is write is mostly closed sourced; so I'm not used to this workflow (sorry!). How do i trigger the automated CI tests here so i can fix issues before a proper review? |
There was a problem hiding this comment.
Code Review
This pull request introduces protections against stack overflow crashes and Denial of Service (DoS) attacks by limiting reference expansions and detecting circular dependencies in SVG masks, patterns, and deferred nodes. Feedback focuses on improving the robustness of these checks by making the expansion counter global to the resolver, applying the limit to more node types, and relocating constants to avoid circular dependencies.
You can't; only Flutter team members are able to trigger CI. |
a4a75e1 to
9a93f3f
Compare
Thanks! |
88af30f to
efea48e
Compare
There was a problem hiding this comment.
Code Review
This pull request implements safeguards against circular references and exponential expansion Denial of Service (DoS) attacks in SVG processing by introducing a cumulative reference expansion limit and tracking active references for masks, patterns, and deferred nodes. A review comment identifies a discrepancy between the expansion limit constant in the code and the value documented in the changelog, suggesting a correction to ensure consistency.
7254af0 to
1f1584d
Compare
1f1584d to
a8d7cc8
Compare
…haustion - Refactors safety expansion threshold limit and error message to package-level constants. - Abstracts structural DFS cycle-guard try-finally scope tracking into a unified generic helper `runWithCycleGuard` inside `util.dart`. - Eliminates duplicate cycle-guarding boilerplate across mask nodes, pattern nodes, and deferred nodes in `resolver.dart` and clip paths in `parser.dart`. - Updates clip path protection test assertions to expect the consolidated error string. Fixes flutter/flutter#186750
…tests using clean String interpolation
a8d7cc8 to
4561c59
Compare
Add comment for recursive loop detection in parser.
Added comments to indicate where recursive loops are detected in mask, deferred, and pattern resolution.
Overview
This PR resolves a critical compile-time Stack Overflow crash and prevents CPU/Memory Denial of Service (DoS) vulnerabilities in the
vector_graphics_compilertool caused by circular references and exponential element expansions (such as Billion Laughs / XML Entity Expansion attacks) in SVG assets.During compilation, the recursive AST resolution phase was vulnerable to:
<use>chains, or circular<use>inside<clipPath>nodes) caused infinite recursion and thread stack exhaustion.This PR implements dual-layer security defenses: local DFS cycle-guards to cleanly break circular loops, and a strict, cumulative reference expansion limit to prevent resource exhaustion.---
Proposed Changes
1. Core DFS Cycle-Guards in AST Resolution (
resolver.dart&parser.dart)_activeMasks,_activePatterns, and_activeDeferred) usingSet<String>inResolvingVisitor.try/finallyblocks to guarantee that IDs are popped from the tracking sets when unwinding the call stack, preventing state leaks.activeDeferred) insidegetClipPath's recursiveextractPathsFromNodehelper to break circular<use>references inside clip paths.2. Cumulative Reference Expansion Cap (
resolver.dart&parser.dart)_deferredExpansionCount) to track the total number of reference expansions (calls tovisitDeferredNodeandextractPathsFromNode) during compilation.10,000cumulative expansions.StateError(SVG contains too many nested reference expansions (possible Denial of Service exploit)), preventing CPU or heap memory exhaustion.3. Regression and Security Unit Tests (
test/parser_test.dart)Added robust test cases covering circular and exponential structures:
Circular Mask Loop Avoidance,Circular Deferred Node Loop Avoidance,Circular Pattern Loop Avoidance, andCircular ClipPath Loop Avoidance.Exponential DAG expansion triggers DoS protection limitandExponential DAG clipPath expansion triggers DoS protection limit(verifying compile-time abortion on a 30-level deep Billion Laughs tree).Why a 1000 Expansion Limit?
1000 is somewhat arbitrary. Benchmarking tests did not reveal any concerns with limit.
Verification Results
vector_graphics_compilerpackage pass successfully.flutter analyzeanddart formatcomplete successfully with "No issues found!".Related Issues
Fixes flutter/flutter#186750
Fixes flutter/flutter#186814
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Appendix
Vibecoded benchmark
Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2