From e3c7f75665d1c3dcb9a6be0130c384b6bea19f9d Mon Sep 17 00:00:00 2001 From: mmporong Date: Tue, 27 Oct 2026 16:19:06 +0900 Subject: [PATCH] [Relax][Frontend][TFLite] Read the keys vector byte width in FlexBufferDecoder FlexBufferDecoder.decode_map always decoded the keys vector of a map with 1-byte offsets. A FlexBuffers map header stores the byte width of its keys vector next to the keys offset, and the builder widens it to 2 bytes once a key string is more than 255 bytes before the vector, for example with long or many keys. Such a map was then decoded into wrong keys or raised UnicodeDecodeError. Read the keys byte width from the map header and use it for the key offsets. The custom options of TFLite_Detection_PostProcess, the only current caller, keep a 1-byte keys vector and decode as before. --- .../relax/frontend/tflite/tflite_flexbuffer.py | 9 +++++++-- tests/python/relax/test_frontend_tflite.py | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/python/tvm/relax/frontend/tflite/tflite_flexbuffer.py b/python/tvm/relax/frontend/tflite/tflite_flexbuffer.py index 148f404f25db..ce415fdece9c 100644 --- a/python/tvm/relax/frontend/tflite/tflite_flexbuffer.py +++ b/python/tvm/relax/frontend/tflite/tflite_flexbuffer.py @@ -135,10 +135,15 @@ def decode_map(self, end, byte_width, parent_byte_width): size_fmt = {1: "