Skip to content

[UB] Access out-of-bounds data when parsing invalid metadata items #208

@henrygab

Description

@henrygab

This code effectively accesses the data at i and at i+1:

picotool/bintool/metadata.h

Lines 257 to 261 in de8ae5a

if (new_p.flags & PICOBIN_PARTITION_FLAGS_HAS_ID_BITS) {
uint32_t low = data[i++];
uint32_t high = data[i++];
new_p.id = (uint64_t)low | ((uint64_t)high << 32);
}

However, the code does not ensure that data[1] will be valid:

picotool/bintool/metadata.h

Lines 237 to 242 in de8ae5a

std::vector<uint32_t> data;
for (unsigned int i=2; i < size; i++) {
data.push_back(*it++);
}
size_t i=0;
while (i < data.size()) {

From https://en.cppreference.com/w/cpp/container/vector/operator_at:

No bounds checking is performed.

Therefore, no guarantee that this will throw an exception (which might be expected), and as a result, clearly getting into undefined behavior.....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions