Skip to content

tree_sitter_cpp_external_scanner_deserialize doesn't bound length against the size of the delimiter buffer #368

Description

@poly2it

void tree_sitter_cpp_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
assert(length % sizeof(wchar_t) == 0 && "Can't decode serialized delimiter!");
Scanner *scanner = (Scanner *)payload;
scanner->delimiter_length = length / sizeof(wchar_t);
if (length > 0) {
memcpy(&scanner->delimiter[0], buffer, length);
}
}

If the function is fed a buffer which exceeds the implicit bound of 64 bytes fed currently, the input can overflow onto the heap. This would be exploitable, if not for the fact that serialize only returns a maximum of MAX_DELIMITER_LENGTH * sizeof(wchar_t) == 64 bytes on Linux and MacOS.

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