Open
Description
Environment
Operating System: Linux Ubuntu 24.04
Version / Commit SHA: VDB 12.0.1
Other: Not related
Describe the bug
nanovdb::io::readGrid(stream)
assumes the input stream supports seeking. If a non-seekable std::istream
is passed (e.g., a custom std::streambuf
that does not implement seekoff
), the function silently fails or hangs, without reporting any error.
To Reproduce
Steps to reproduce:
Define a minimal non-seekable std::streambuf
:
struct NonSeekableBuf : std::streambuf {
std::vector<char> buffer;
NonSeekableBuf(const std::string& filename) {
std::ifstream file(filename, std::ios::binary);
if (!file) throw std::runtime_error("Failed to open file");
file.seekg(0, std::ios::end);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
buffer.resize(size);
file.read(buffer.data(), size);
setg(buffer.data(), buffer.data(), buffer.data() + size);
}
// disable seek
std::streampos seekoff(std::streamoff, std::ios_base::seekdir, std::ios_base::openmode) override {
return std::streampos(std::streamoff(-1));
}
std::streampos seekpos(std::streampos, std::ios_base::openmode) override {
return std::streampos(std::streamoff(-1));
}
};
Use it with nanovdb::io::readGrid
:
NonSeekableBuf buf("volume.nvdb");
std::istream in(&buf);
auto handle = nanovdb::io::readGrid<nanovdb::HostBuffer>(in);
Observe that:
- No grid is returned
- No error is thrown
- May hang in certain configurations
Expected behavior
The function should:
- Fail early and clearly if the stream is not seekable
- Optionally support non-seekable input by reading sequentially (if feasible)
Additional context
(Add any other context about the problem here.)