Fix TSA #2816218: suppress Flawfinder false positive on Cython read-loop iterator (pydevd_frame_evaluator.c)#2030
Merged
StellaHuang95 merged 1 commit intoMay 28, 2026
Conversation
…oop iterator Flawfinder's buffer/read rule (CWE-120, CWE-20) fires whenever an identifier named "read" appears inside a loop, assuming it refers to the POSIX read() syscall. The Cython 3.x ModuleStateLookup boilerplate in __Pyx_State_ConvertFromInterpIdAsIndex uses "read" as the name of a pointer iterator that walks data->table, bounded by end = read + data->count. There is no syscall and no unbounded buffer access -- this is a false positive. Add an inline /* Flawfinder: ignore */ annotation to the flagged line in the Cython-generated pydevd_frame_evaluator.c and extend the existing post-processing block in setup_pydevd_cython.py so the annotation is re-applied automatically whenever Cython regenerates the .c files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rchiodo
approved these changes
May 28, 2026
Contributor
rchiodo
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Internal Flawfinder compliance scan flagged a
forloop containing the identifierreadin the Cython-generatedpydevd_frame_evaluator.c.FlawFinder/buffer/read— "Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20)"src/debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_evaluator.cWhat Flawfinder reported
This is the Cython 3.x runtime boilerplate function
__Pyx_State_ConvertFromInterpIdAsIndex(per-interpreter module-state compaction). The same function is emitted into every Cython-generated.cfile.Why this is a false positive
Flawfinder's
buffer/readrule fires whenever the identifierreadappears inside a loop, on the assumption it refers to the POSIXread()syscall (which can return fewer bytes than requested). Herereadis a variable name — specifically a pointer iterator walkingdata->table— not a syscall.The loop is provably bounded:
end = read + data->countdefines the upper bound.read < endguaranteesreadnever advances past the last valid slot.writeonly advances on successful copies and always trailsread, sowrite <= read <= endis invariant.Fix
/* Flawfinder: ignore */to the flagged line. This is the documented Flawfinder suppression token (seeflawfinder --help).c_file_contents.replace(...)to the existing post-processing block insetup_pydevd_cython.pyso the suppression is automatically re-applied if Cython is re-run to regenerate the.cfile.The annotation is a C block comment — equivalent to whitespace at the lexer level, with zero effect on compiled output or runtime behavior.
Verification
Ran Flawfinder 2.0.20 locally against the modified file:
flawfinder --neverignore(suppressions disabled)readtoken on that line)The originally flagged warning is silenced, and the positive control with
--neverignoreconfirms the suppression is what's silencing it.Risk
Zero behavioral change. The
.cfile edit is a comment; thesetup_pydevd_cython.pyedit is astr.replace()that is a no-op if the matched text is absent (so it's safe even if Cython upstream changes its output).Related
The same Cython boilerplate appears in two sibling generated files and is tracked separately:
_pydevd_sys_monitoring_cython.cpydevd_cython.cEach is fixed in its own PR.