Skip to content

Throw InvalidDataException when Skia cannot decode an image - #155

Open
Adamstuhltrager wants to merge 1 commit into
Bond-009:masterfrom
Adamstuhltrager:fix-skia-undecodable-image
Open

Adamstuhltrager wants to merge 1 commit into
Bond-009:masterfrom
Adamstuhltrager:fix-skia-undecodable-image

Conversation

@Adamstuhltrager

Copy link
Copy Markdown

SKCodec.Create returns null for data Skia does not recognise, and SKBitmap.Decode returns null when the codec fails to produce pixels (for example a truncated progressive JPEG, where the header is readable but GetPixels returns InvalidInput). Both were dereferenced without a check, so callers get a NullReferenceException from inside the encoder with no hint that the input was at fault. Jellyfin users hit this on every library scan for any corrupt poster or logo; see jellyfin/jellyfin#12106 and jellyfin/jellyfin#3687, which carry the same stack trace.

This routes codec creation and bitmap decoding through helpers that throw InvalidDataException with a descriptive message, throws FileNotFoundException up front for a missing file, and documents both on the public overloads.

Tests cover unrecognised data, a truncated progressive JPEG fixture (459 bytes, generated from a gradient) and a missing file, for all four public overloads. The SkiaSharp test project now copies TestData/ to the output directory.

🤖 Generated with Claude Code

SKCodec.Create returns null for data Skia does not recognise, and
SKBitmap.Decode returns null when the codec fails to produce pixels, for
example on a truncated progressive JPEG. Both were dereferenced without a
check, so callers saw a NullReferenceException with no indication that the
input was at fault.

Route codec creation and bitmap decoding through helpers that throw an
InvalidDataException with a descriptive message instead, and throw
FileNotFoundException up front for a missing file. Add tests covering
unrecognised data, a truncated progressive JPEG fixture and a missing
file for every public overload.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant