scancode.io icon indicating copy to clipboard operation
scancode.io copied to clipboard

XLSX export truncations overwrite the last data column.

Open dikshaa2909 opened this issue 8 months ago • 3 comments

When returning truncated results in the XLSX export (add_xlsx_worksheet in scanpipe/pipes/output.py), if an error occurs , the error warning string overwrites the last legitimate data column instead of writing to the separate xlsx_errors column.

This destroys exported user data for the last column (or the only column, if there is only 1 export field) across all large project exports while leaving the intended error column completely empty.

Reproduce

  1. Export a project to XLSX using the add_xlsx_worksheet method using any number of fields.
  2. Have one data row contain a string field that exceeds Excel's 32767 string length limit.
  3. Observe the output .xlsx file. The final data field will inexplicably be replaced by the truncation warning, and the actual data is permanently lost. Concurrently, the trailing xlsx_errors column will be blank.

The existing unit tests miss this because they test an export with exactly 1 data column The len(["foo"]) - 1 = 0 causes the error to overwrite Column 0 instead of writing to the new Column 1, destroying the data. The test only string-matches the raw XML instead of verifying column positions.

dikshaa2909 avatar Mar 10 '26 13:03 dikshaa2909

Hi @AyanSinhaMahapatra ,

I was looking into the XLSX export logic in add_xlsx_worksheet and noticed this behavior. My local testing confirms that when a truncation occurs, the warning string currently overwrites the data in the final column of the row.

I wanted to check if this was an intentional design choice for some reason, or if I am correct in interpreting this as an off-by-one error in the errors_col_index calculation?

If you agree this is a bug, I have already verified a fix locally along with updated unit tests in scanpipe/tests/pipes/test_output.py (which refactored to use multi-column checks to catch this displacement).

I'd be happy to submit a Pull Request if you'd like!

dikshaa2909 avatar Mar 10 '26 13:03 dikshaa2909

I put in a pull request to handle this issue. The number is #2117

Basically, I went through the changes to make sure everything lines up right. In the file scanpipe/pipes/output.py, there was this indexing thing for columns that wasnt quite working. It used len(fields) minus one, which made the truncation warning show up in the wrong spot. It was overwriting the last data column instead of going into xlsx_errors like it should. So I changed it to just len(fields). That seems to put it where it belongs now.

Then, to check if this holds up, I added a test case in scanpipe/tests/pipes/test_output.py. Its for multiple fields, and it specifically looks at this behavior. I figure thatll catch if something slips back in later.

The tests all ran fine on my machine and in the CI setup. If you see anything off during review, just say so, and I can tweak it.

Gaurav5189 avatar Mar 26 '26 08:03 Gaurav5189

I have submitted a fix for this in PR #2181.

prajakta128 avatar Jun 25 '26 05:06 prajakta128