Skip to content

_encode_varint cannot handle 0 #130

@P403n1x87

Description

@P403n1x87

The following exception is thrown when a TryBegin is the very first entry in a Bytecode object

value = 0, set_begin_marker = True

    @staticmethod
    def _encode_varint(value: int, set_begin_marker: bool = False) -> Iterator[int]:
        # Encode value as a varint on 7 bits (MSB should come first) and set
        # the begin marker if requested.
        temp: List[int] = []
        assert value >= 0
        while value:
            temp.append(value & 63 | (64 if temp else 0))
            value >>= 6
        if set_begin_marker:
>           temp[-1] |= 128
E           IndexError: list index out of range

It looks like the _encode_varint helper is failing to handle a value of 0 in this case. In Python 3.11 it is likely that the first opcode is e.g. RESUME, so in real Python code this issue might not occur.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions