Harden vendored nim scanner against empty deserialize buffer

state_deserialize() dereferenced &buffer[0] and passed it to
indent_vec_deserialize()'s nonnull argument even when buffer was NULL /
buffer_len was 0 (the initial empty-state deserialize), tripping UBSan. Return
early after clearing state when there is nothing to deserialize.
This commit is contained in:
Martin Vogel
2026-06-03 02:13:30 +02:00
parent 31f7438ce0
commit 22fe48147e
+6
View File
@@ -360,6 +360,12 @@ _nonnull_(1) static void state_deserialize(
DBG("error: no buffer but buffer length > 0");
return;
}
/* Empty/absent buffer: nothing to deserialize. Return early so we never
* pass a null/zero-length pointer to indent_vec_deserialize's nonnull arg. */
if (!buffer || buffer_len == 0) {
state_clear(self);
return;
}
unsigned idx = 0;
state_clear(self);