mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 23:11:19 +00:00
Stacks in Context can grow when eval is run, and if they are implemented as SmallVector, the growing can cause a reallocation. Meanwhile for stacks that hold larger structs/classes, we hold onto the pointer into the stack instead of copying out. This can cause a UAF when reallocation happens. StableStack never reallocates when growing, as it is represented by a vector of pointers to arrays, where each array is a factor larger than the previous one. This prevents UAF from occurring when we run eval while holding a pointer into a stack. This solves a similar problem that our ValuesStores previously solved in #5576. In that case, we also represent them as a vector of pointers to arrays. The difference being our ValueStores are meant to grow but not shrink, and they are built around the ID concept where IDs happen to be an index into the store.