-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GDAL segfault loading massive VRT raster into std::vector #9713
Comments
This isn't a GDAL bug. You are just asking for something impossible First there is an integer overflow occurring in your code when you do |
Thanks for pointing out the error in my code. I was not intending to load the whole terrain, I was just hoping the library would fail in a safer way. Is it possible to add a C++ API that can take in an STL container for the buffer argument that is size-aware and add some error protection? I would be happy to contribute such an alternative. For anyone else who finds this, here is my solution, which will ensure it throws with an allocation failure rather than overflow and segfault: static_assert(std::numeric_limits<uint64_t>::max() >= std::numeric_limits<uint32_t>::max() * std::numeric_limits<uint32_t>::max());
buffer.resize(static_cast<uint64_t>(destWidth) * static_cast<uint64_t>(destHeight)); |
although that's not easily tested, I believe GDAL should be able to load the data if you had sufficient RAM and patience... :-)
That would be a reasonable enhancement |
What is the bug?
When you have a massive VRT dataset, and call RasterIo on the dataset, it can segfault. I am using a
std::vector
as the buffer.Even if your hardware allocated the buffer, it can fail.
Steps to reproduce the issue
main.cpp
CMakeLists.txt
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug cmake --build build ./build/vrt_loader /vsizip/vsicurl/https://terrain.ardupilot.org/SRTM1/ap_srtm1.zip/ap_srtm1.vrt
backtrace
Versions and provenance
Linux Ubuntu 22.04
Additional context
I would like some information on how to protect against this - user-supplied datasets may be large.
See gazebosim/gz-common#596 (comment) for more context on how this is a problem in a user-application.
The text was updated successfully, but these errors were encountered: