Skip to content

fix(files): do not read an ordinary data row as a total row - #9538

Open
Harvey DU (Luckyou-d) wants to merge 3 commits into
crewAIInc:mainfrom
Luckyou-d:fix/spreadsheet-total-row-needs-no-label
Open

Harvey DU (Luckyou-d) wants to merge 3 commits into
crewAIInc:mainfrom
Luckyou-d:fix/spreadsheet-total-row-needs-no-label

Conversation

@Luckyou-d

Copy link
Copy Markdown

Summary

total_row treats the last row as a total when a numeric column's last value equals the sum of the column above it. Any ascending arithmetic sequence satisfies that, so ordinary data silently disappeared from describe, value_counts, group_by and the overview's column profile while rows still showed it:

item,amount     ->  describe: "2 rows (its total row, row 4, is left out)"
a,1
b,2
c,3

2,4,6 and 10,20,30 behave the same. total_row is also the function the strix/cursor reviews of #9389 kept landing on.

Change

A row that carries its own label is data, however neatly its numbers add up; a real total row has no row label, or one of the recognised ones. Both shapes the existing tests cover keep working - ["Total", 6] through the label branch, [None, 6] through the empty first cell.

Verification

  • pytest lib/crewai-files/tests/spreadsheets/test_answers.py -> 75 passed; the three new sequence cases fail on main and pass here, and the labelled/unlabelled total-row cases still pass
  • pytest lib/crewai-files/tests/spreadsheets/test_reading.py -> 85 passed (160 together with test_answers)
  • ruff check and ruff format --check clean on both files

Fixes #9537

`total_row` treats the last row as a total when a numeric column's last value
equals the sum of the column above it. Any ascending sequence satisfies that,
so 1/2/3, 2/4/6 and 10/20/30 lost their last row from `describe`,
`value_counts`, `group_by` and the column profile, while `rows` still showed it.

A row that carries its own label is data, however neatly its numbers add up: a
real total row has no row label, or one of the recognised ones. Both shapes the
existing tests cover keep working - `["Total", 6]` through the label branch and
`[None, 6]` through the empty first cell.

Fixes crewAIInc#9537
@strix-security

strix-security Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Strix Security Review

Warning

This pull request has 28 commits after the last Strix review (a39e7f3). Strix has not reviewed these changes.
Automatic review on push is off for this repository. To review the latest changes, tag @strix-security in a comment, or turn on re-review on push.

✅ No open security findings.

PR summary: Fixes spreadsheet total-row detection so an ordinary data row whose numbers happen to add up (an ascending sequence such as 1/2/3 or 10/20/30) is no longer mistaken for a total and silently dropped from describe, value_counts, group_by and the overview's column profile; a row counts as a total only when its first cell is blank or a recognised total label.

Review summary

The PR narrows the total-row heuristic in crewai_files.spreadsheets.answers.total_row: a last row whose numbers add up is no longer treated as a total when its first cell carries its own label, and only a blank or recognised total label restores the old behaviour. Review found no security issue. The change is strictly one-directional (total_row can only newly return None, never a new index), its callers already handle the "no total row" case, and the newly included cell values reach only the same plain-text, framing-prefixed aggregate output that the rows operation and the overview's sample rows already emitted before the change. Cell text never becomes SQL, a pattern, a filter expression, or code, and the only regex applied to it is an anchored literal alternation over whitespace-collapsed text, so there is no backtracking exposure. A side effect worth the author's attention is functional rather than security-related: a genuine total row whose label is outside the recognised list ("Subtotal", "Balance", localised wording) or a numeric first cell in a single-column numeric sheet is now kept as data and double-counts in sums.

Ruled out (2)
  • Does the new labelled-data gate cause genuine total rows to be aggregated as data, producing wrong sums in describe and group_by?
    The behaviour is real for labels outside the recognised list and for numeric first cells, but it only misstates an aggregate for the owner of the spreadsheet they supplied, crosses no auth or tenant boundary, and grants no capability the file's author did not already have.
  • Does the change route attacker-controlled cell content to a sink (code execution, query building, regex, terminal output) that it previously could not reach?
    The `rows` operation and the overview's sample rows already emitted arbitrary cell text through the same whitespace-collapsing formatter, and cell values are never interpolated into SQL, patterns, filters or executable code anywhere in the package.

Review 1 on this PR · a39e7f3 · requested Nov 18 09:06 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

This branch has not been deployed

No deployments
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.

[BUG] An ascending numeric sequence is misread as a total row, hiding the last data row

1 participant