python / cpython

The Python programming language
https://www.python.org
Other
63.49k stars 30.4k forks source link

Overflow if `ast.AST.end_col_offset` is absurdly large #126860

Open federicovalenso opened 4 hours ago

federicovalenso commented 4 hours ago

Bug report

Bug description:

c = ast.parse('x = 1')
c.body[0].end_col_offset = 2**31-1
c.body[0].end_col_offset
2147483647
code = compile(c, "", "exec")

It leads to overflow in _PyPegen_raise_error. This is also true for col_offset (just replace c.body[0].end_col_offset)

CPython versions tested on:

3.11

Operating systems tested on:

Linux

picnixz commented 4 hours ago

Can you provide me an example where it could lead to invalid result?

federicovalenso commented 4 hours ago

I tried, but failed... But that doesn't mean there won't be someone who can, and that could lead to unexpected problems. Or am I paranoid? :)))

picnixz commented 4 hours ago

I would say that it depends on whether it's reachable or not and whether it will be used or not. Let's ask @pablogsal if this is worth fixing.