Skip to content

DW-41: Add net462 build on SkiaSharp 4 with no ImageSharp dependency (ImageSharp 2.x CVEs) - #160

Open
Sawraz-IS wants to merge 8 commits into
system-memory-4.6-familyfrom
skiasharp-net462
Open

Sawraz-IS wants to merge 8 commits into
system-memory-4.6-familyfrom
skiasharp-net462

Conversation

@Sawraz-IS

@Sawraz-IS Sawraz-IS commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

SixLabors.ImageSharp 2.x is end-of-life and its CVEs will not be patched. ImageSharp 3.x does not support .NET Framework. Our .NET Framework customers therefore had no patched path, because they consumed the netstandard2.0 build, which depends on ImageSharp 2.1.13.

This PR adds a dedicated net462 build that has no SixLabors.ImageSharp dependency at all. Stacked on #159, which adds the System.Memory 4.6.x family that SkiaSharp 4 needs.

What changed

Engine (IronSoftware.Drawing.Common/SkiaEngine/, compiled only for NETFRAMEWORK)

  • Internal types mirror the ImageSharp API subset AnyBitmap uses (Image<TPixel>, pixel structs, Mutate, encoders, metadata). This lets AnyBitmap.cs keep a single code path with a using switch.
  • SkiaSharp 4.153.3 (MIT, actively patched): decode for PNG/JPEG/GIF/BMP/WebP (incl. animated frames and EXIF orientation), Catmull-Rom resize, JPEG and WebP encoding.
  • BitMiracle.LibTiff.NET (already a dependency): TIFF decode, all pages, thumbnails skipped. TIFF encoding already went through LibTiff.
  • Our own PNG, BMP and GIF writers keep ImageSharp's behaviour that AnyBitmap relies on: PNG keeps gray/GA/RGB/RGBA at 8/16 bit plus pHYs; BMP is 24/32 bpp with alpha and resolution; GIF uses per-frame palettes, transparency, loop and delays.
  • Header readers fill in what SkiaSharp doesn't expose: source pixel layout (so BitsPerPixel matches ImageSharp's choice) and resolution (PNG pHYs, JFIF/EXIF, BMP).

Public API on net462

  • The 42 implicit operators to and from SixLabors.ImageSharp types are compiled out on net462 (AnyBitmap 6, Color 18, Point/PointF/Size/SizeF 2 each, Rectangle 4, RectangleF 2, CropRectangle 4).
  • Every other public member is identical to netstandard2.0. I verified this with a metadata diff of both builds; the only differences are those 42 operators.
  • SVG on net462 uses Svg.Skia 5.2.3 (MIT, the maintained successor), because SkiaSharp.Svg 1.60 calls APIs that SkiaSharp 4 removed. It stays an optional install, like SkiaSharp.Svg today, and gives a clear "install Svg.Skia" error when missing.

Packaging

  • csproj: netstandard2.0;net462;net60. net462 references SkiaSharp 4.153.3, SixLabors.Fonts 1.0.0 and Svg.Skia. netstandard2.0 and net60 are unchanged.
  • nuspec: new .NETFramework4.6.2 group (Abstractions, SkiaSharp 4.153.3, SixLabors.Fonts 1.0.0, LibTiff, System.Memory family) plus lib/net462. Release notes list the breaking changes.
  • SystemPackages.props now applies to net462 too.
  • Test-SystemAssemblyReferences.ps1: .NET Framework groups are checked against the package's matching lib/net4x folder (System.Memory 4.6.3 lib/net462 = 4.0.5.0). The netstandard2.0 group keeps the conservative minimum.

Verification

Check Result
Build netstandard2.0, net462, net60 (Debug + Release), whole solution ✅
Tests net48 (against net462 build) ✅ 379/379
Tests net8.0 (ImageSharp path, unchanged) ✅ 423/423
Test-SystemAssemblyReferences.ps1 ✅ 5 references, incl. net462
Pack (nuget.exe 6.2.1) ✅ lib/net462 present; net462 group has no ImageSharp
net48 consumer app from the packed nupkg ✅ PNG/JPEG/GIF/BMP/WebP/TIFF load and re-export to all 6 formats; no SixLabors.ImageSharp.dll in output; System.Memory 4.0.5.0 binds
net48 consumer + Svg.Skia ✅ SVG loads
net48 consumer pinning SkiaSharp 2.88.7 ⛔ NU1605 downgrade error at restore (fails loudly at build, not at runtime)
Public API diff net462 vs netstandard2.0 only the 42 ImageSharp operators differ

Test changes: on net48, tests that exercise the removed ImageSharp casts are wrapped in #if !NET48. The new SkiaEngineFunctionality (net48 only, 17 tests) covers the same behaviours through the public API: pixel get/set, lossless and lossy round trips, transparency, crop, redact, rotate, resize, multi-frame GIF/TIFF and bit depth. CreateMultiFrameTiff_Preserves_Rgb24_Pixels compares against the engine's own JPEG decode on net48, because libjpeg-turbo and ImageSharp differ by ±2 levels.

Why SkiaSharp 4 on net462 (not 2.88.x)

  • The SkiaSharp 2.88 line's last release is 2.88.9 (2024-11-07). It hasn't had a release in over two years and is built on Skia m88 (2020). The 3.x/4.x lines get regular patch releases with backports, including for the bundled libpng/libjpeg-turbo/libwebp. net462 uses 4.153.3 (2026-11-06).
  • DW-41 asks for a .NET Framework configuration with no unpatched image-decoding dependency (customer ticket 50817893128), so moving net462 from ImageSharp 2.x to SkiaSharp 2.88 wouldn't close it.
  • netstandard2.0/net6.0/net8.0 still reference SkiaSharp 2.88.7. That's existing exposure this PR doesn't change; moving them to SkiaSharp 4 (plus SkiaSharp.Svg → Svg.Skia) is proposed as a separate, all-targets follow-up.

Review round (DW-41)

  • Native buffer safety: all engine pixel buffers go through PixelBuffer.Allocate<T>, which validates width × height (computed in long, ≤ 2 GB) before native SkiaSharp/LibTiff code writes into them. Dimensions are also checked right after SKCodec.Create. Regression test: Png_WithOverflowingDimensions_IsRejected.
  • Octree quantizer: the root is now reducible and Reduce() reports progress, so re-encoding a 1-bit/2-bit palette PNG whose content needs more colours no longer hangs. It quantises to 2^bitDepth colours, as ImageSharp does. Test: OneBitPalettePng_RedactedWithAnotherColor_SavesAsPng.
  • DPI readback (all targets): AnyBitmap converted pixels-per-metre/cm to DPI with Math.Ceiling, so a 72-DPI PNG (2835 px/m) read as 73 and a 96-DPI one (3780) as 97. It now rounds to nearest. Multi-page TIFFs also ignored ResolutionUnit=cm, so a 96-DPI page written by CreateMultiFrameTiffBytes (stored as 37.795 px/cm) read back as 37; centimetres are now converted (8218b67). Tests: ResolutionReadbackFunctionality (PNG 72/96/300/600, single- and multi-page TIFF in inch and cm, and a multi-frame TIFF round trip). This changes the reported DPI on netstandard2.0/net6.0/net8.0 as well, always towards the correct value.
  • Svg.Skia: the message and release notes name the tested major ("Svg.Skia 5.x, tested with 5.2.3"), and an incompatible major is reported clearly.
  • System. check (DW-41: Upgrade System.Memory family to 4.6.x for netstandard2.0, declare it in the nuspec, add CI reference check #159):* a missing declared version is reported as a mismatch instead of throwing, and path handling works on Linux/macOS agents. The release notes mention NU1605 for projects pinning System.Memory < 4.6.3.
  • Second review round (a476710): the deploy pipeline now signs lib/net462 as well; single-page TIFFs with unassociated alpha keep straight colours on net462 (as ImageSharp does); a new net481 test target loads the netstandard2.0 build (ImageSharp 2.1.13 + BigTIFF guard) and runs as a Windows CI job next to net48; and the DPI rounding change is in the release notes.
  • Verified: net462 and netstandard2.0 build, net48 tests 406/406 (SkiaSharp build), net481 451/451 (netstandard2.0 build), and the System.* check passes. net6.0/net8.0 need the Six Labors licence and run only in CI.

⚠️ Release coordination (breaking for .NET Framework)

  • Products compiled against the netstandard2.0 Drawing build that use ImageSharp casts will hit MissingMethodException in .NET Framework apps that pick up this package's net462 lib.
  • SkiaSharp-typed members now bind to SkiaSharp 4 on net462. Products compiled against SkiaSharp 2.88 that call removed SkiaSharp APIs would fail the same way.
  • Ship this only together with net462 builds of IronPdf / IronPdf.Core / IronWord / IronXL / IronOcr / IronBarCode.
  • Apps that pin SkiaSharp 2.x get a restore error and must move to SkiaSharp ≥ 4.153.1.

Not in this PR

  • .NET 6/8 still use ImageSharp 3.1.12 (patched). Moving those to the SkiaSharp engine as well is proposed for the next major, with a deprecation cycle.

Update: now includes DW-38 (ImageSharp 3.2.0 / 4.1.3, net8.0, BigTIFF guard, ImageSharpLoader)

PR #159 now targets DW-38-imagesharp-v4-framework-support and has DW-38 merged in. This branch merges that, so publishing from skiasharp-net462 gives one Drawing version with all of it:

Target Engine
net462 SkiaSharp 4.153.3 + LibTiff, no ImageSharp
netstandard2.0 ImageSharp 2.1.13 + BigTIFF guard
net6.0 ImageSharp 3.2.0
net8.0 ImageSharp 4.1.3

Changes made while merging:

  • ImageSharpLoader: the public type is ImageSharp-typed, so it is compiled out on net462. That makes it the 43rd ImageSharp-typed API missing on .NET Framework; products must gate their calls (e.g. npoi ImageUtils). An internal SkiaEngine.ImageSharpLoader keeps AnyBitmap's call sites shared.
  • BigTIFF (CVE-2026-106116) on net462: TIFF goes through LibTiff. DW-38's AnyBitmap BigTIFF tests run on net48 and fail fast as required.
  • PNG re-encode on net462: keeps a decoded PNG's palette or 1/2/4-bit grayscale encoding, matching ImageSharp and DW-38's new test.
  • Release notes: the BigTIFF guard and ImageSharpLoader are scoped to the ImageSharp targets.

Verified locally:

  • net462 and netstandard2.0 build.
  • net48 tests: 390/390.
  • System.* reference check passes.
  • net6.0/net8.0 were not built locally: ImageSharp 3.2/4.1 need the Six Labors licence file, which only CI has. Please rely on CI for those targets.

🤖 Generated with Claude Code

@mee-ironsoftware mee-ironsoftware left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Automated /scrutinize review — not yet read by @mee-ironsoftware.

Automated review — verdict: fix-then-ship

Blockers: 1 · Major: 2 · Nits: 1 — 4 inline, 0 in this body.

This is deliberately a comment only: it never approves and never requests changes. The verdict above is advisory; @mee-ironsoftware will follow up.

Adds a net462 build with an internal SkiaSharp 4 + LibTiff engine mirroring the ImageSharp API, dropping ImageSharp 2.x for .NET Framework. Biggest issue: the decoder sizes the pixel buffer it hands to native SKCodec.GetPixels with unchecked width*height, so a crafted PNG header can wrap it to a tiny buffer that Skia then overruns — a memory-safety bug in a PR whose purpose is security.


Reviewed head SHA e888f2ee038451c8d99dcd7d17f767fc71537817. Re-request review on this PR to get a fresh pass.

@Sawraz-IS Sawraz-IS changed the title Add net462 build on SkiaSharp 4 with no ImageSharp dependency (ImageSharp 2.x CVEs) DW-41: Add net462 build on SkiaSharp 4 with no ImageSharp dependency (ImageSharp 2.x CVEs) Dec 3, 2026

@ikkyuland ikkyuland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikkyu's bot auto-review (not from human)

Status: REQUEST_CHANGES. 1 blocking and 3 suggestions inline, 1 suggestion in this body.

This review is for head 8218b67. Commit ec895e4 fixes the unchecked width * height buffers and the octree loop, and I checked both fixes in the full files. One packaging defect is still open: the deploy pipeline does not sign the new lib/net462 DLL. The other notes are about a TIFF alpha difference from ImageSharp, lost netstandard2.0 test coverage, and release notes.

Findings not anchored to a changed line

  • ⚠️ suggestion — Check the release version before you publish. The repository does not set the package version. CI/azure-pipelines-build.yml makes it from the IronDrawingVersions variable group and a counter, or from inputNuGetVersion. The latest public version is 2026.11.5 (tag 2026.11.5 = 451786e). IronPdf#1146 depends on Drawing 2026.3.23-prerelease, which agrees with a variable group that still holds 2026.3. That version sorts below 2026.11.5. A project that already has 2026.11.5 gets NU1605, and a >= 2026.11.5 dependency never resolves to it. This release also removes 43 public members on .NET Framework, so the version must clearly come after 2026.11.5. Fix: publish with inputNuGetVersion set to 2026.12.x or higher (or update the variable group), then rebuild the products against that version. (bot)

Comment thread NuGet/IronSoftware.Drawing.nuspec Resolved
@Sawraz-IS
Sawraz-IS requested a review from ikkyuland December 3, 2026 06:08
@Sawraz-IS

Copy link
Copy Markdown
Collaborator Author

@ikkyuland Thanks for the review. Every inline item is addressed in a476710: net462 DLL signing, straight alpha for single-page TIFFs, a net481 CI job that tests the netstandard2.0 build, and the DPI release note.

On the release-version suggestion in the review body: agreed. 2026.3.23-prerelease was only an interim prerelease for porting the products. The combined build will be published with inputNuGetVersion set above 2026.11.5 (2026.12.x), and the product PRs will be rebuilt against that version before anything merges. Re-review requested.

@mee-ironsoftware mee-ironsoftware self-assigned this Dec 3, 2026

@ikkyuland ikkyuland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ikkyu's bot auto-review (not from human)

Status: APPROVED (re-review of 8218b67...a476710)

This delta fixes the blocking issue and the three suggestions from my last review:

  • sign_drawing_libraries_dll.yml now signs the net462 IronSoftware.Drawing.Common.dll.
  • The net462 TIFF decoder divides by alpha again when EXTRASAMPLES is UNASSALPHA. TiffAlphaFunctionality runs on net48 (SkiaSharp build), net481 (netstandard2.0 build) and net80, so it also shows that the builds agree.
  • The new net481 test job runs the netstandard2.0 (ImageSharp 2.1.13) build in CI.
  • The release notes now describe the DPI rounding change on all targets.

I found no new problems in the delta.

Note for the release: publish a version that sorts above 2026.11.5. IronPdf.Core#333, IronPdf#1146, IronWord#140 and IronXL#298 cannot drop their 2026.3.23-prerelease pin until that version is on nuget.org (latest there today: 2026.11.5).

CI: the PR validation check shows "skipping" on this head, so I did not see a green run of the new net481 job.

@mee-ironsoftware mee-ironsoftware left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of e888f2e → a476710. All 8 earlier items (4 from the automated review, 4 from the second bot pass) are addressed and I checked each one in the code: PixelBuffer sizes every buffer that native code writes into using long maths, the net462 DLL is signed, TIFF unassociated alpha is fixed, the net481 job tests the netstandard2.0 build, the Svg.Skia message names 5.x, and the DPI release note is in.

One major remains, inline: the octree change no longer hangs, but it can turn the whole image into a single colour. I reproduced this on net48. Please fix it before release. The two nits are optional.

… dependency, including the DW-38 integration previously done in merge commits
…rs, stop the octree quantizer looping when colours cannot be reduced, round pHYs DPI to nearest, name the Svg.Skia version, and move net462 to SkiaSharp 4.153.3
…a for single-page TIFFs, test the netstandard2.0 build on net481 in CI, and note the DPI rounding change
…palette cannot be reduced further, size the pre-decode check by the decoded pixel type, and share the netstandard2.0 dependency versions with the net481 tests
@Sawraz-IS
Sawraz-IS force-pushed the system-memory-4.6-family branch from 9a9275e to 366bd1f Compare December 3, 2026 07:21
…ll step to store version information in the deploy pipeline
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.

3 participants