d2lang/d2 · error

checksum error in table: %v

Error message

checksum error in table: %v

What it means

Sfnt2Woff converts an SFNT font (TTF/OTF) to WOFF. It validates each table's checksum (except the 'head' table) before writing WOFF table metadata; a mismatch means the source font buffer is corrupt or was modified after its tables were written.

Source

Thrown at lib/font/font.go:124

			Length:   binary.BigEndian.Uint32(table[SFNT_OFFSET_LENGTH:]),
		}

		entries = append(entries, entry)
	}
	sort.Slice(entries, func(i, j int) bool {
		return string(entries[i].Tag) < string(entries[j].Tag)
	})

	sfntSize := uint32(SIZE_OF_SFNT_HEADER + int(numTables)*SIZE_OF_SFNT_TABLE_ENTRY)
	tableInfo := make([]byte, int(numTables)*SIZE_OF_WOFF_ENTRY)

	for i := 0; i < len(entries); i++ {
		tableEntry := entries[i]
		if string(tableEntry.Tag) != "head" {
			alignTable := fontBuf[tableEntry.Offset : tableEntry.Offset+longAlign(tableEntry.Length)]

			if calcChecksum(alignTable) != tableEntry.CheckSum {
				return nil, fmt.Errorf("checksum error in table: %v", string(tableEntry.Tag))
			}
		}

		binary.BigEndian.PutUint32(tableInfo[i*SIZE_OF_WOFF_ENTRY+WOFF_ENTRY_OFFSET_TAG:], binary.BigEndian.Uint32(tableEntry.Tag))
		binary.BigEndian.PutUint32(tableInfo[i*SIZE_OF_WOFF_ENTRY+WOFF_ENTRY_OFFSET_LENGTH:], tableEntry.Length)
		binary.BigEndian.PutUint32(tableInfo[i*SIZE_OF_WOFF_ENTRY+WOFF_ENTRY_OFFSET_CHECKSUM:], tableEntry.CheckSum)

		sfntSize += longAlign(tableEntry.Length)
	}

	sfntOffset := uint32(SIZE_OF_SFNT_HEADER + len(entries)*SIZE_OF_SFNT_TABLE_ENTRY)
	csum := calcChecksum(fontBuf[:SIZE_OF_SFNT_HEADER])
	for i := 0; i < len(entries); i++ {
		tableEntry := entries[i]

		b := make([]byte, SIZE_OF_SFNT_TABLE_ENTRY)
		binary.BigEndian.PutUint32(b[SFNT_OFFSET_TAG:], binary.BigEndian.Uint32(tableEntry.Tag))
		binary.BigEndian.PutUint32(b[SFNT_OFFSET_CHECKSUM:], tableEntry.CheckSum)

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Re-download or restore the font from a trusted source and verify its hash
  2. Ensure no text-mode processing (git autocrlf, base64 mangling) altered the binary
  3. Open the font in a validator (e.g. fonttools ttx) to identify the failing table reported in %v
  4. If embedding fonts, ship them as binary assets with checksum verification
Defensive patterns

Strategy: validation

Validate before calling

f, err := os.Open(fontPath)
if err != nil {
    return err
}
info, _ := f.Stat()
if info.Size() < 12 {
    return errors.New("font file too small to be valid SFNT")
}
head := make([]byte, 4)
f.Read(head)
if !bytes.Equal(head, []byte{0, 1, 0, 0}) && !bytes.Equal(head, []byte("OTTO")) {
    return fmt.Errorf("not a TTF/OTF font: magic %x", head)
}

Type guard

func isSFNT(data []byte) bool {
    return len(data) >= 4 && (bytes.Equal(data[:4], []byte{0, 1, 0, 0}) || bytes.Equal(data[:4], []byte("OTTO")))
}

Try / catch

woff, err := font.Sfnt2Woff(fontBuf)
if err != nil {
    if strings.HasPrefix(err.Error(), "checksum error in table") {
        log.Printf("corrupt font table: %v — re-fetch asset", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Sfnt2Woff with a font whose table checksums don't match the computed calcChecksum of its aligned table data — typically a truncated, bit-corrupted, or hand-patched font file.

Common situations: Fonts fetched over the network with incomplete downloads, fonts stored in version control/assets corrupted by line-ending or encoding filters, or fonts modified by tooling without recomputing checksums.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/c7746dc87c7ec71e. Report an issue: GitHub.