{"record":{"id":"0cf781fcea1d5381","repo":"vitessio/vitess","slug":"invalid-signature-for-trie2-0x-08x","errorCode":null,"errorMessage":"invalid signature for Trie2: 0x%08x","messagePattern":"invalid signature for Trie2: 0x%08x","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/mysql/icuregex/internal/utrie/utrie2.go","lineNumber":381,"sourceCode":"\t\t/** Null index and data blocks, not shifted. */\n\t\tindex2NullOffset, dataNullOffset uint16\n\n\t\t/**\n\t\t * First code point of the single-value range ending with U+10ffff,\n\t\t * rounded up and then shifted right by UTRIE2_SHIFT_1.\n\t\t */\n\t\tshiftedHighStart uint16\n\t}\n\n\tvar header utrie2Header\n\theader.signature = bytes.Uint32()\n\n\tswitch header.signature {\n\tcase 0x54726932:\n\tcase 0x32697254:\n\t\treturn nil, errors.New(\"unsupported: BigEndian encoding\")\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"invalid signature for Trie2: 0x%08x\", header.signature)\n\t}\n\n\theader.options = bytes.Uint16()\n\theader.indexLength = bytes.Uint16()\n\theader.shiftedDataLength = bytes.Uint16()\n\theader.index2NullOffset = bytes.Uint16()\n\theader.dataNullOffset = bytes.Uint16()\n\theader.shiftedHighStart = bytes.Uint16()\n\n\tvar width int\n\tswitch header.options & 0xf {\n\tcase 0:\n\t\twidth = 16\n\tcase 1:\n\t\twidth = 32\n\tdefault:\n\t\treturn nil, errors.New(\"invalid width for serialized UTrie2\")\n\t}","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/mysql/icuregex/internal/utrie/utrie2.go#L363-L399","documentation":"UTrie2FromBytes rejects serialized Unicode Trie2 (UTrie2) data whose leading 4-byte signature/magic does not match the expected 'Tri2' (0x54726932) value. This guards the deserializer in go/mysql/icuregex/internal/utrie/utrie2.go against parsing random or corrupted bytes as a case-mapping trie. Big-endian ('2irT', 0x32697254) is recognized but explicitly unsupported and yields a different error.","triggerScenarios":"Calling UTrie2FromBytes (via readData) with data whose first 4 bytes are not 0x54726932 — e.g. a truncated or corrupt embedded ICU data blob, wrong offset into the byte slice, a big-endian serialized trie, or passing entirely unrelated bytes.","commonSituations":"Regenerating or replacing ICU data files with a different tool/version that emits big-endian output; manual slicing of the data section at a wrong offset; corrupted binary blobs embedded in a build; porting data from another ICU distribution.","solutions":["Verify the byte slice passed to UTrie2FromBytes starts exactly at the trie header with the 4-byte magic 0x54726932 ('Tri2' little-endian)","Regenerate the ICU/trie data with the standard tooling so it is serialized little-endian, and re-embed it","Check that any preceding header fields consumed by readData (options/lengths) were not skipped, shifting the read offset","If the source data is big-endian (0x32697254), convert it to little-endian — the parser rejects big-endian outright"],"exampleFix":"// before: slicing from the start of the file\ntrie, err := utrie2.UTrie2FromBytes(blob)\n// after: skip the file header to the trie data section\ntrie, err := utrie2.UTrie2FromBytes(blob[headerLen:])","handlingStrategy":"validation","validationCode":"func validTrie2(b []byte) bool {\n    return len(b) >= 4 && binary.LittleEndian.Uint32(b) == 0x54726932\n}\nif !validTrie2(data) { return errors.New(\"not a little-endian Trie2 blob\") }","typeGuard":"func isTrie2Data(b []byte) bool {\n    return len(b) >= 4 && string(b[0:4]) == \"Tri2\"\n}","tryCatchPattern":null,"preventionTips":["Check the first 4 bytes of the blob for 0x54726932 before deserializing","Regenerate trie data only with the project's standard little-endian tooling","Pin/verify checksums of embedded ICU data blobs in CI","Log the signature value (hex) when deserialization fails to spot endianness vs offset issues"],"tags":["go","serialization","unicode","data-corruption"],"backgroundTag":"invalid-binary-signature","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}