{"record":{"id":"9b6accc4bf2d63d0","repo":"AvaloniaUI/Avalonia","slug":"could-not-load-the-tablename-table","errorCode":null,"errorMessage":"Could not load the '{TableName}' table.","messagePattern":"Could not load the '(.+?)' table\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/Fonts/Tables/MaxpTable.cs","lineNumber":64,"sourceCode":"            MaxContours = maxContours;\n            MaxCompositePoints = maxCompositePoints;\n            MaxCompositeContours = maxCompositeContours;\n            MaxZones = maxZones;\n            MaxTwilightPoints = maxTwilightPoints;\n            MaxStorage = maxStorage;\n            MaxFunctionDefs = maxFunctionDefs;\n            MaxInstructionDefs = maxInstructionDefs;\n            MaxStackElements = maxStackElements;\n            MaxSizeOfInstructions = maxSizeOfInstructions;\n            MaxComponentElements = maxComponentElements;\n            MaxComponentDepth = maxComponentDepth;\n        }\n\n        public static MaxpTable Load(GlyphTypeface fontFace)\n        {\n            if (!fontFace.PlatformTypeface.TryGetTable(Tag, out var table))\n            {\n                throw new InvalidOperationException($\"Could not load the '{TableName}' table.\");\n            }\n\n            var binaryReader = new BigEndianBinaryReader(table.Span);\n\n            return Load(ref binaryReader);\n        }\n\n        private static MaxpTable Load(ref BigEndianBinaryReader reader)\n        {\n            // Version 0.5 (CFF/CFF2 fonts):\n            // | Version16Dot16 | version   | 0x00005000 for version 0.5      |\n            // | uint16         | numGlyphs | The number of glyphs in the font|\n            \n            // Version 1.0 (TrueType fonts):\n            // | Version16Dot16 | version                | 0x00010000 for version 1.0                          |\n            // | uint16         | numGlyphs              | The number of glyphs in the font                    |\n            // | uint16         | maxPoints              | Maximum points in a non-composite glyph             |\n            // | uint16         | maxContours            | Maximum contours in a non-composite glyph           |","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/Fonts/Tables/MaxpTable.cs#L46-L82","documentation":"The 'maxp' table declares maximum values (glyph count, stack depth, instruction storage) the rasterizer uses to size buffers. MaxpTable.Load calls PlatformTypeface.TryGetTable(Tag, out ...) and throws when TryGetTable returns false, meaning the table directory has no 'maxp' entry. Fonts without maxp are unusable for layout.","triggerScenarios":"Constructing a GlyphTypeface over a font stream/buffer where the sfnt table directory omits 'maxp'; loading a WOFF/WOFF2 whose deobfuscation produced a truncated sfnt; loading a TTC collection whose selected face index points at a face missing maxp.","commonSituations":"A binary-truncated download of a web font where the table directory survived but table data did not; an in-progress or hand-assembled font file (fontTools build gone wrong); reading a CFF2 OTF variant produced by an older toolchain that omitted maxp version 0.5.","solutions":["Run 'ttx -l font.ttf' (or fc-scan) on the asset and confirm 'maxp' is listed with a non-zero length.","Re-fetch or re-export the font from a trusted source; a missing required table indicates corruption.","If loading from a stream, verify the stream Length matches the file size on disk before handing it to GlyphTypeface.","Guard untrusted font assets with a try/catch on InvalidOperationException around GlyphTypeface construction and fall back to a system font."],"exampleFix":"// before\nusing var gt = new GlyphTypeface(stream);\n\n// after\nGlyphTypeface gt;\ntry { gt = new GlyphTypeface(stream); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"'maxp'\"))\n{\n    _logger.LogError(\"Font asset missing maxp table (corrupt?): {Msg}\", ex.Message);\n    throw new InvalidDataException($\"Font asset is corrupt or incomplete: missing 'maxp' table.\", ex);\n}","handlingStrategy":"validation","validationCode":"static bool HasRequiredTables(string path)\n{\n    try { using var fs = File.OpenRead(path); using var r = new BinaryReader(fs);\n        r.ReadUInt32(); r.ReadUInt16(); var n = r.ReadUInt16();\n        var tags = new HashSet<string>();\n        for (int i = 0; i < n; i++) { fs.Position = 12 + i*16; tags.Add(new string(r.ReadChars(4))); }\n        return tags.Contains(\"maxp\");\n    } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { _gt = new GlyphTypeface(stream); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"'maxp'\"))\n{ throw new InvalidDataException($\"Font asset is corrupt: {ex.Message}\", ex); }","preventionTips":["Re-fetch fonts from trusted sources when the file size looks wrong.","Validate stream Length against the asset's expected size before parsing.","Catch InvalidOperationException around GlyphTypeface construction and surface the asset path."],"tags":["fonts","font-parsing","maxp","glyph-typeface","corruption"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}