Skip to content

[flutter_svg] SvgNetworkLoader parses non-2xx error pages as SVG, hiding the real failure #195162

Closed
flutter/packages
#13403

Description

@francisrath

What package does this bug report belong to?

flutter_svg

What target platforms are you seeing this bug on?

Android, iOS

Have you already upgraded your packages?

Yes

Dependency versions

flutter_svg 2.3.1 (also present on current main of flutter/packages). No other dependencies are involved — the bug is in SvgNetworkLoader itself.

Steps to reproduce

  1. Point SvgPicture.network (or SvgNetworkLoader) at a URL whose server answers with a non-2xx status and an HTML body, e.g. a 404 or a 503 error page.
  2. Let the picture load.

Expected results

The load fails with an error that names the HTTP status and URL, so the cause is visible (e.g. an http.ClientException).

Actual results

SvgNetworkLoader.prepareMessage returns response.bodyBytes without checking response.statusCode, so the HTML error page is handed to the SVG parser and fails as StateError: Bad state: Invalid SVG data. The actual 404/503 is lost.

We ran into this in production: during a short backend 503 outage, a request got the server's error page, and our crash reporter showed only "Invalid SVG data".

Code sample

Code sample
// Any URL that returns 404 with an HTML body.
final bytes = await const SvgNetworkLoader('https://example.com/missing.svg')
    .prepareMessage(null);
// bytes is the 404 page; parsing it later throws
// StateError: Bad state: Invalid SVG data

Screenshots or Videos

No response

Logs

Logs
StateError: Bad state: Invalid SVG data
  parser.dart: SvgParser._parseTree
  parser.dart: SvgParser.parse
  vector_graphics_compiler.dart: parse
  vector_graphics_compiler.dart: encodeSvg
  loaders.dart: SvgLoader._load.<fn>.<fn>

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.44.8, on macOS 27.0.1 26A434 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[!] Xcode - develop for iOS and macOS (Xcode 27.0)
[✓] Chrome - develop for the web
[✓] Connected device (3 available)
[✓] Network resources

Activity

  1. added
    packageflutter/packages repository. See also p: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    p: flutter_svgThe Flutter SVG drawing packages
    on Oct 23, 2026
  2. mbcorona commented on Oct 23, 2026

    @mbcorona
    Member

    HI @francisrath , thanks for the report.
    Routing to the engine team to evaluate the issue and PR.

  3. github-actions commented on Nov 11, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.team-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions