Previously we were allocating memory on the message's arena every time we performed a `map[key]` or `map.get(key)` operation. This is unnecessary, as the key's data is only needed ephemerally, for the duration of the lookup, and we can therefore alias the Python object's string data instead of copying it. This required fixing a bug in the convert.c operation. Previously in the `arena==NULL` case, if the user passes a bytes object instead of a unicode string, the code would return a pointer to a temporary Python object that had already been freed, leading to use-after-free. I fixed this by referencing the bytes object's data directly, and using utf8_range to verify the UTF-8. Fixes: https://github.com/protocolbuffers/protobuf/issues/14571 PiperOrigin-RevId: 578563555pull/14583/head
parent
8defef58f4
commit
1711ebd455
4 changed files with 24 additions and 18 deletions
Loading…
Reference in new issue