Skip to content

Improve localTaint predicate performance in STLContainer. - #1198

Open
MichaelRFairhurst wants to merge 2 commits into
mainfrom
michaelrfairhurst/optimise-container-taint-predicate
Open

MichaelRFairhurst wants to merge 2 commits into
mainfrom
michaelrfairhurst/optimise-container-taint-predicate

Conversation

@MichaelRFairhurst

Copy link
Copy Markdown
Collaborator

Previous implementation was using nomagic to prevent bad joins from being introduced in localTaint. However, this forces the evaluator to construct the entire graph of local taint paths, which is about 25 million tuples on pandas.

This blocks updating to new dataflow where the performance issues get worse. The evaluator creates additionalTaintStep+, a relation with 6.7 billion rows. This is done via a higher-order-predicate and is surprisingly fast (8sec). However, the next step takes the +-style transitive closure and tries to make the * version, by unioning the + version with a scan of all dataflow nodes n into tuples (n, n)`. I don't know why this union OOMs, to be honest, but the crash stack trace includes an "unsorted relation writer," which maybe indicates that the OOM comes from trying to sort the 6.7 billion values. In any case, I'm satisfied that we shouldn't be constructing a 6.7 billion relation here.

Fixed by identifying the root candidate set of expressions that come from container function calls that we're interested in, which is 799 nodes on pandas, and then the transitive relation containerTaint is just 1765 rows on old dataflow. On new dataflow this is 701 sources and 5779 nodes in the transitive closure.

Description

please enter the description of your change here

Change request type

  • Release or process automation (GitHub workflows, internal scripts)
  • Internal documentation
  • External documentation
  • Query files (.ql, .qll, .qls or unit tests)
  • External scripts (analysis report or other code shipped as part of a release)

Rules with added or modified queries

  • No rules added
  • Queries have been added for the following rules:
    • rule number here
  • Queries have been modified for the following rules:
    • CTR55-CPP
    • Potentially all other queries involving iterators

Release change checklist

A change note (development_handbook.md#change-notes) is required for any pull request which modifies:

  • The structure or layout of the release artifacts.
  • The evaluation performance (memory, execution time) of an existing query.
  • The results of an existing query in any circumstance.

If you are only adding new rule queries, a change note is not required.

Author: Is a change note required?

  • Yes
  • No

🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.

  • Confirmed

Reviewer: Confirm that either a change note is not required or the change note is required and has been added.

  • Confirmed

Query development review checklist

For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:

Author

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Reviewer

  • Have all the relevant rule package description files been checked in?
  • Have you verified that the metadata properties of each new query is set appropriately?
  • Do all the unit tests contain both "COMPLIANT" and "NON_COMPLIANT" cases?
  • Are the alert messages properly formatted and consistent with the style guide?
  • Have you run the queries on OpenPilot and verified that the performance and results are acceptable?
    As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
  • Does the query have an appropriate level of in-query comments/documentation?
  • Have you considered/identified possible edge cases?
  • Does the query not reinvent features in the standard library?
  • Can the query be simplified further (not golfed!)

Previous implementation was using nomagic to prevent bad joins from
being introduced in localTaint. However, this forces the evaluator to
construct the entire graph of local taint paths, which is about 25
million tuples on pandas.

This blocks updating to new dataflow where the performance issues get
worse. The evaluator creates `additionalTaintStep+`, a relation with
6.7 billion rows. This is done via a higher-order-predicate and is
surprisingly fast (8sec). However, the next step takes the `+`-style
transitive closure and tries to make the `*` version, by unioning the
`+` version with a scan of all dataflow nodes n into tuples (n, n)`. I
don't know why this union OOMs, to be honest, but the crash stack
trace includes an "unsorted relation writer," which maybe indicates
that the OOM comes from trying to sort the 6.7 billion values. In any
case, I'm satisfied that we shouldn't be constructing a 6.7 billion
relation here.

Fixed by identifying the root candidate set of expressions that come
from container function calls that we're interested in, which is 799
nodes on pandas, and then the transitive relation `containerTaint` is
just 1765 rows on old dataflow. On new dataflow this is 701 sources
and 5779 nodes in the transitive closure.
Copilot AI balanced review requested due to automatic review settings September 16, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The semantic rewrite appears sound, but its compilation and dataset-scale performance could not be independently validated.

Review effort: Balanced
Findings: None

What changed in this PR

Scopes local taint evaluation to relevant STL container call results, avoiding construction of the full taint graph while preserving query semantics.

Changes:

  • Adds source-filtered container taint predicates.
  • Adds the required performance change note.
  • Unverified: shared-query execution and OpenPilot performance results.
File Description
cpp/​common/​src/​codingstandards/​cpp/​standardlibrary/​STLContainers.qll Restricts local taint traversal to relevant container calls.
change_notes/​2026-09-16-improve-iterator-access-check-performance.md Documents the performance optimization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants