MemoryManagement<Storage>::reserve()
can panic with index out of bounds
#243
Labels
bug
Something isn't working
cubecl_runtime::memory_management::memory_manage::MemoryManagement<Storage>::reserve()
(below) can panic whensize
is bigger than any availablepool
.cubecl/crates/cubecl-runtime/src/memory_management/memory_manage.rs
Lines 275 to 288 in 3882ed2
In my case (running
burn
) my program attempted to allocate 2_925_527_040 bytes with pools max sizes: [0] 4_028_128 B [1] 4_028_128 B [2] 32_225_024 [3] [4] 2_062_401_536 B. Sopool_ind
was computed as5
and&mut self.pools[pool_ind]
panicked.The function can panic in edge-cases because per docs
partition_point()
requires that:and the condition seems to not be checked at any point.
The same issue also occurs a few lines lower in
alloc()
.The solution is probably a simple bounds check or capping
pool_ind
topools.len() - 1
or some more complex error handling.Happy to help with solving the problem.
The text was updated successfully, but these errors were encountered: