Skip to content

[BUG] nanovdb::io::readGrid requires seekable istream but fails silently #2041

Open
@yzx9

Description

@yzx9

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions