#37583 [SC-Low] Incorrect For Annotation Parsing
Description
Brief/Intro
Vulnerability Details
class ForParser:
def __init__(self, code):
self._code = code
self.annotations = {}
self._current_annotation = None
self._state = ParserState.NOT_RUNNING
self._current_for_loop = None
def consume(self, token):
# state machine: we can start slurping tokens soon
if token.type == NAME and token.string == "for":
# note: self._state should be NOT_RUNNING here, but we don't sanity
# check here as that should be an error the parser will handle.
self._state = ParserState.START_SOON
self._current_for_loop = token.start
if self._state == ParserState.NOT_RUNNING:
return False
# state machine: start slurping tokens
if token.type == OP and token.string == ":":
self._state = ParserState.RUNNING
# sanity check -- this should never really happen, but if it does,
# try to raise an exception which pinpoints the source.
if self._current_annotation is not None:
raise SyntaxException(
"for loop parse error", self._code, token.start[0], token.start[1]
)
self._current_annotation = []
return True # do not add ":" to tokens.
# state machine: end slurping tokens
if token.type == NAME and token.string == "in":
self._state = ParserState.NOT_RUNNING
self.annotations[self._current_for_loop] = self._current_annotation or []
self._current_annotation = None
return False
if self._state != ParserState.RUNNING:
return False
# slurp the token
self._current_annotation.append(token)
return TrueImpact Details
References
Proof of Concept
Proof of Concept
Previous#38277 [BC-Insight] Potential Out-of-Range Panic in `UnmarshalJSON()` of `HexOrDecimal256`Next#37582 [SC-Low] Incorrect HexString Parsing Leads To Compilation Error Or Type Confusion
Was this helpful?