I think you should store `sizeInBytes` in a local variable first so that no other thread can ever see a value that is greater than the maximum size?