You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the nice tutorial, it's been very easy to follow. Just a small issue I noticed so far regarding buffer alignment:
Step 34 has a potential buffer overflow if the size of the index buffer is not already a multiple of four. Specifically, if the size ends up being padded, writing to the buffer will read in adjacent memory to indexData without any warning, as it is now strictly larger in size. It would probably be best to handle this properly by padding the CPU side of things as well, and warn readers that this is necessary.
I think the simplest solution is to use an aligned allocator for std::vector, for example as per this answer on stackoverflow, with 4 byte or larger alignment. This ensures that the write will always happen to safely allocated memory.
petar-andrejic
changed the title
Buffer overflow in step 34
Buffer overflow/alignment issues in step 34
Aug 18, 2024
Thanks for the nice tutorial, it's been very easy to follow. Just a small issue I noticed so far regarding buffer alignment:
Step 34 has a potential buffer overflow if the size of the index buffer is not already a multiple of four. Specifically, if the size ends up being padded, writing to the buffer will read in adjacent memory to indexData without any warning, as it is now strictly larger in size. It would probably be best to handle this properly by padding the CPU side of things as well, and warn readers that this is necessary.
Minimal working example of the issue, using dawn:
The output is
since the buffer overshot the extent SomeData.cpuData and ended up reading data from SomeData.someOtherData as well.
The text was updated successfully, but these errors were encountered: