Skip to content

Commit

Permalink
add format string length verification in get_formatter
Browse files Browse the repository at this point in the history
Fix damian-m-g#12 crash with strange format on xlsx file - damian-m-g#12
  • Loading branch information
gvollant committed May 17, 2024
1 parent 9774d74 commit 5a7ca20
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/xlsx_drone.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,10 @@ static xlsx_cell_category get_related_category(const char *format_code, int form
* - current_analyzed_index: the index pointing to a specific char of *format_code*.
*/
static xlsx_formatter get_formatter(const char *format_code, int current_analyzed_index) {
int length_format_code = (int)strlen(format_code);
if (current_analyzed_index >= length_format_code)
return XLSX_FORMATTER_UNKNOWN;

switch(format_code[current_analyzed_index]) {
case 'm': case 'h': case 's': case 'y': case 'd': {
// "[Red]" case
Expand Down Expand Up @@ -829,6 +833,9 @@ static xlsx_formatter get_formatter(const char *format_code, int current_analyze
if((++i == current_analyzed_index) && (!quotes_open)) {
break;
}
if(i >= length_format_code) {
return XLSX_FORMATTER_UNKNOWN;
}
}
}

Expand Down

0 comments on commit 5a7ca20

Please sign in to comment.