Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix out-of-bounds linenos in findsource
  • Loading branch information
picnixz committed Aug 26, 2024
commit be64bc8b4f87491298750506297166c1da642ad0
5 changes: 4 additions & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,10 @@ def findsource(object):
firstlineno = vars(object)['__firstlineno__']
except (TypeError, KeyError):
raise OSError('source code not available')
return lines, firstlineno - 1
lnum = firstlineno - 1
if lnum >= len(lines) or lnum < 0:
raise OSError('lineno is out of bounds')
return lines, lnum

if ismethod(object):
object = object.__func__
Expand Down