{"record":{"id":"af773a61f20f66b7","repo":"SubtitleEdit/subtitleedit","slug":"unable-to-access-bitmap-pixel-data","errorCode":null,"errorMessage":"Unable to access bitmap pixel data.","messagePattern":"Unable to access bitmap pixel data\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/libse/BluRaySup/BluRaySupParser.cs","lineNumber":188,"sourceCode":"                {\n                    return new SKBitmap(1, 1);\n                }\n\n                var w = data[0].Width;\n                var h = data[0].Height;\n\n                if (w <= 0 || h <= 0 || data[0].Fragment?.ImageBuffer?.Length == 0)\n                {\n                    return new SKBitmap(1, 1);\n                }\n\n                // Unpremul (not Premul) as FillPixels/PutPixelFast below write straight, non-premultiplied RGBA.\n                // Opaque here would make Skia drop the alpha channel when encoding (transparent areas turn black).\n                var bm = new SKBitmap(w, h, SKColorType.Rgba8888, SKAlphaType.Unpremul);\n                var pixelPtr = bm.GetPixels(); // Writable pixel buffer\n                if (pixelPtr == IntPtr.Zero)\n                {\n                    throw new InvalidOperationException(\"Unable to access bitmap pixel data.\");\n                }\n\n                unsafe\n                {\n                    var buf = data[0].Fragment.ImageBuffer;\n                    var pixelData = new Span<byte>(pixelPtr.ToPointer(), bm.ByteCount); // Create writable span\n                    var pal = DecodePalette(palettes);\n\n                    var ofs = 0;\n                    var xpos = 0;\n\n                    for (var index = 0; index < buf.Length;)\n                    {\n                        var b = buf[index++] & 0xff;\n\n                        if (b == 0 && index < buf.Length)\n                        {\n                            b = buf[index++] & 0xff;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/BluRaySup/BluRaySupParser.cs#L170-L206","documentation":"Thrown when an SkiaSharp SKBitmap, freshly allocated with dimensions w×h and Rgba8888/Unpremul colortype, returns a zero pointer from GetPixels(). The BluRaySupParser decodes PGS subtitle fragments straight into the bitmap's native pixel buffer via an unsafe Span, so a null pointer means there is no writable backing store to write decoded RGBA into.","triggerScenarios":"Constructing a very large SKBitmap that exhausts native memory; running on a platform where SkiaSharp cannot pin/allocate the pixel buffer (e.g. constrained GPU/SkiaSharp build); w/h coming from a malformed PGS packet that passes the >0 guard but yields an allocation failure.","commonSituations":"Corrupt or hand-edited Blu-ray SUP files with oversized dimension fields; low-memory containers; mismatched SkiaSharp version where GetPixels() behavior differs; processing many subtitles in a batch without disposing bitmaps (native heap pressure).","solutions":["Validate w and h against a sane upper bound before allocating the bitmap and return the 1×1 fallback instead of throwing.","Ensure SKBitmap is disposed after use to release native memory (use using/finally around each decode).","Upgrade/downgrade SkiaSharp to a version known to allocate pixel buffers for the target runtime.","Catch InvalidOperationException at the caller and surface a user-friendly 'cannot render this subtitle' message rather than crashing the import."],"exampleFix":"// before\nvar bm = new SKBitmap(w, h, SKColorType.Rgba8888, SKAlphaType.Unpremul);\nvar pixelPtr = bm.GetPixels();\nif (pixelPtr == IntPtr.Zero)\n{\n    throw new InvalidOperationException(\"Unable to access bitmap pixel data.\");\n}\n\n// after\nconst int MaxDim = 4096;\nif (w > MaxDim || h > MaxDim)\n{\n    return new SKBitmap(1, 1);\n}\nusing var bm = new SKBitmap(w, h, SKColorType.Rgba8888, SKAlphaType.Unpremul);\nvar pixelPtr = bm.GetPixels();\nif (pixelPtr == IntPtr.Zero)\n{\n    bm.Dispose();\n    return new SKBitmap(1, 1);\n}","handlingStrategy":"validation","validationCode":"const int MaxDim = 4096;\nif (w <= 0 || h <= 0 || w > MaxDim || h > MaxDim) { /* skip decode */ }","typeGuard":null,"tryCatchPattern":"try { var bm = parser.Decode(...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"bitmap pixel data\")) { /* log + skip subtitle */ }","preventionTips":["Dispose every SKBitmap after use to avoid native heap exhaustion.","Cap decoded subtitle dimensions at a sane maximum before allocation.","Pin the SkiaSharp version used during testing."],"tags":["skia","bitmap","memory","blu-ray","pgs","subtitle"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}