Skip to content

read_csv: stop dta missing values overflowing missing_ranges - #441

Open
ziyziy89 wants to merge 1 commit into
WizardMac:devfrom
ziyziy89:dta-missing-ranges-bound
Open

ziyziy89 wants to merge 1 commit into
WizardMac:devfrom
ziyziy89:dta-missing-ranges-bound

Conversation

@ziyziy89

Copy link
Copy Markdown
Contributor

dta_add_missing_double and dta_add_missing_date in the CSV to .dta path store each missing value as a range at missing_ranges[2idx] and [2idx+1], but the only limit is the Stata tag check ('a' + idx <= 'z', 26 values) while readstat_missingness_t has room for 16 ranges. A metadata.json column with 17 or more entries in missing.values (or 17 category codes inside missing.low/high) overwrites missing_ranges_count and the rest of the variable, after which the count holds the stored value's bits and the next index comes from the JSON. With 18 DATE missing values (1960-01-01 to 1960-01-16, then 1960-01-20 and 1960-01-21), readstat input.csv metadata.json output.dta hits an ASan heap-buffer-overflow WRITE at mod_dta.c:54.

Exit with an error once the array is full, next to the existing tag-limit check in both helpers. mod_sav goes through readstat_variable_add_missing_double_range, which already bounds the array, so only the dta module needs it.

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.

1 participant