tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.49k stars 418 forks source link

Fix format::number_format #628

Closed mfsv closed 2 years ago

mfsv commented 2 years ago

In case number_format() is called on a format that does not have a value format set, numberformat() calls d->number_format_id.get() on an invalid number_formatid or dereferences d->parent->number_formats.end() causing a crash.

This can happen when calling cell::is_date() on a cell that has type 'number' without a number format but some other styling set. This might never occur in spreadsheet files created by commercial applications but xlnt certainly allows to create such a file. We therefore fix number_format by returning the general number format as a fallback. Additionally, consider to add a method format::has_number_format() and change cell::is_date() accordingly.

Attached there is a test file were the problem occurs when cell::is_date() is called on cell A1. Test.xlsx

tfussell commented 2 years ago

Thanks for the contribution and sorry it took so long to merge.