mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 06:06:09 -06:00
[GH-ISSUE #512] worksheet_data_validation_cell: heap overflow and infinite loop when value_list contains 256+ items #398
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/libxlsxwriter#398
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @billdenney on GitHub (Apr 6, 2026).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/512
Summary
Passing a
NULL-terminatedvalue_listarray with 256 or more entries toworksheet_data_validation_cell()(orworksheet_data_validation_range()) causes the process to hang indefinitely and ultimately overflow a heap buffer.Reproduction
Compile with AddressSanitizer (
-fsanitize=address) to get an immediate crash instead of a hang.Expected behaviour
worksheet_data_validation_cell()should returnLXW_ERROR_255_STRING_LENGTH_EXCEEDED. The combined CSV string for 256 single-character items is 511 characters (256 items + 255 commas), which exceeds Excel's 255-character limit for validation list strings.Actual behaviour
The process crashes. With AddressSanitizer it crashes immediately with a heap-buffer-overflow report.
Root cause
The internal helper
_validation_list_length()uses auint8_tloop counter and exits early once the running total reachesLXW_VALIDATION_MAX_STRING_LENGTH(255). For 256 single-character items it exits after counting 128 of them (running total 256 ≥ 255 triggers the guard) and returns 255 after thelength--adjustment. The caller's checklength > 255evaluates to false, so the list is accepted._validation_list_to_csv()is then called. It also uses auint8_tloop counter. After processing index 255,i++wraps back to 0.list[0]is non-NULL, so the loop restarts from the beginning and runs forever, continuously callingstrcatinto a 1023-byte heap buffer until the buffer overflows and the heap is corrupted.Suggested resolution
Two changes in
src/worksheet.c.In
_validation_list_length(): change the counter type tosize_tand remove the early-exit length guard so the function always returns the actual total length of the list. The caller's existinglength > LXW_VALIDATION_MAX_STRING_LENGTHcheck then correctly rejects over-length lists before_validation_list_to_csv()is ever reached.