Skip to content

Nit: fix range check in vcdecoder.cc #82

@maksverver

Description

@maksverver

In vcdecoder.cc, there is a check to see if the copy address falls within the decoded buffer:

if ((decoded_address < 0) || (decoded_address > here_address)) {

Here, the expression (decoded_address > here_address) should be replaced by (decoded_address >= here_address). Otherwise, if decoded_address == here_address, you'll go into an infinite loop here:

open-vcdiff/src/vcdecoder.cc

Lines 1221 to 1228 in 868f459

while (size > (target_bytes_decoded - address)) {
// Recursive copy that extends into the yet-to-be-copied target data
const size_t partial_copy_size = target_bytes_decoded - address;
CopyBytes(&target_segment_ptr[address], partial_copy_size);
target_bytes_decoded += partial_copy_size;
address += partial_copy_size;
size -= partial_copy_size;
}

This isn't a problem in practice, because VCDiffAddressCache already validates the returned address (correctly, this time):

} else if (decoded_address >= here_address) {

So the check in vcdecoder.cc should be unnecessary. Still, if it's kept, it should be correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions