Skip to content

Infinite loop in osmium::memory::Buffer::reserve_space #202

@botanegg

Description

@botanegg

I catch an inf loop by simple code using Buffer(size_t capacity, auto_grow auto_grow = auto_grow::yes) ctor

    // reproducing code
    osmium::memory::Buffer node_buffer{0, osmium::memory::Buffer::auto_grow::yes};
    osmium::builder::NodeBuilder builder{node_buffer};

Buffer(size_t capacity, auto_grow auto_grow = auto_grow::yes) uses new unsigned char[capacity] and set m_memory to non-null (that is "valid buffer"), however m_capacity is 0;
Because m_capacity is 0 reserve_space is infinite:

                        size_t new_capacity = m_capacity * 2;
                        while (m_written + size > new_capacity) {
                            new_capacity *= 2;
                        }

Simple fixing m_memory(capacity ? new unsigned char[capacity] : nullptr) leads to assertion

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