dotnet/wpf · error · InvalidOperationException

Decompression of packet data failed.

Error message

Decompression of packet data failed.

What it means

Preconditions for native packet decompression failed or the native decompression call produced a bad result (size out of range, null output buffer, or non-zero HR). The library throws 'Decompression of packet data failed.' as a deliberately vague guard against attacks on the ISF decompressor.

Solutions

  1. Re-save or re-export the ink file from a trusted application
  2. Validate the ISF stream (chunk sizes consistent with buffer length) before deserializing
  3. Catch InvalidOperationException in stroke deserialization and degrade gracefully (drop the stroke/ink payload)

Example fix

// before
var strokes = new StrokeCollection(stream); // throws Decompression of packet data failed
// after
try { strokes = new StrokeCollection(stream); }
catch (InvalidOperationException) { strokes = null; ReportCorruptIsf(); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (chunkSize > input.Length) throw new InvalidDataException("ISF packet chunk exceeds buffer");

Type guard

bool IsSanePacketChunk(byte[] b, uint declared) => b != null && declared <= (uint)b.Length;

Try / catch

try { return new StrokeCollection(stream); } catch (InvalidOperationException) { ReportCorruptInk(); return null; }

Prevention

When it happens

Trigger: Loading ISF strokes where the compressed packet chunk's declared size exceeds the actual input length, the decompressed-buffer request fails, or AlgoModule.DecompressPacketData returns an inconsistent result.

Common situations: Truncated or maliciously crafted .isf files; ink streams across clipboard/persistence round-trips losing bytes; third-party ISF writers emitting invalid chunk sizes.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/7cf836af2e011458. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/Compress.cs:89

            byte[] compressedInput,
            ref uint size,
            int[] decompressedPackets)
        {
#if OLD_ISF
            //
            // lock to prevent multi-threaded vulnerabilities 
            //
            lock (_compressSync)
            {
#endif
                if (compressedInput == null ||
                    size > compressedInput.Length ||
                    decompressedPackets == null)
                {
                    //we don't raise any information that could be used to attack our ISF code
                    //a simple 'ISF Operation Failed' is sufficient since the user can't do 
                    //anything to fix bogus ISF
                    throw new InvalidOperationException(StrokeCollectionSerializer.ISFDebugMessage(SR.DecompressPacketDataFailed));
                }
#if OLD_ISF
                uint size2 = size;
#endif

                size = AlgoModule.DecompressPacketData(compressedInput, decompressedPackets);

#if OLD_ISF
                MS.Win32.Penimc.CompressorSafeHandle safeCompressorHandle = (compressor == null) ?
                                                    MS.Win32.Penimc.CompressorSafeHandle.Null :
                                                    compressor._compressorHandle;

                int[] decompressedPackets2 = new int[decompressedPackets.Length];
                byte algo = AlgoModule.NoCompression;
                int hr = MS.Win32.Penimc.UnsafeNativeMethods.IsfDecompressPacketData(safeCompressorHandle,
                                                                                            compressedInput,
                                                                                            ref size2,
                                                                                            (uint)decompressedPackets2.Length,

View on GitHub (pinned to 81131a70a4)