summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-03-15 21:48:34 +0100
committerLuboš Luňák <l.lunak@collabora.com>2022-03-15 22:39:37 +0100
commitad1f6e62298612f4b277708b813a219ba390f1b0 (patch)
tree303f8885d681235d2cc764a1cd04952223316f01 /sc
parent1fa46653315810a579009f712f2c1bbdf1f5fd44 (diff)
handle broken row ranges in excel import
LIBREOFFICE-39G76603.xlsx from crashtesting has broken data cause assertion failures about the ranges being sorted (because the ranges overlap and StyleRowRangeComp needs and assumes that they do not). Changing the std::unique() call to remove ranges that compare equal (which is not the same as being equal, due to how StyleRowRangeComp compares) and sorting again seems to drop all problematic ranges. (I'm not adding the problematic file to tests as loading it takes a lot of time.) Change-Id: If6ac94959a649a641d02fd703d33edddbdf0fb85 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131637 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/inc/sheetdatabuffer.hxx7
-rw-r--r--sc/source/filter/oox/sheetdatabuffer.cxx10
2 files changed, 9 insertions, 8 deletions
diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index c212c8f0e09d..a6bec5a55807 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -206,13 +206,6 @@ private:
return lhs.mnEndRow<rhs.mnStartRow;
}
};
- struct StyleRowRangeCompEqual
- {
- bool operator() (const RowRangeStyle& lhs, const RowRangeStyle& rhs) const
- {
- return lhs.mnStartRow==rhs.mnStartRow && lhs.mnEndRow == rhs.mnEndRow;
- }
- };
typedef ::o3tl::sorted_vector< RowRangeStyle, StyleRowRangeComp > RowStyles;
typedef ::std::map< sal_Int32, RowStyles > ColStyles;
typedef ::std::vector< RowRangeStyle > TmpRowStyles;
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 259e3190107b..82fc10f35069 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -373,7 +373,15 @@ void SheetDataBuffer::addColXfStyles()
{
TmpRowStyles& s = rowStyles.second;
std::sort( s.begin(), s.end(), StyleRowRangeComp());
- s.erase( std::unique( s.begin(), s.end(), StyleRowRangeCompEqual()), s.end());
+ s.erase( std::unique( s.begin(), s.end(),
+ [](const RowRangeStyle& lhs, const RowRangeStyle& rhs)
+ // Synthetize operator== from operator < . Do not create an actual operator==
+ // as operator< is somewhat specific (see StyleRowRangeComp).
+ { return !StyleRowRangeComp()(lhs,rhs) && !StyleRowRangeComp()(rhs,lhs); } ),
+ s.end());
+ // Broken documents may have overlapping ranges that cause problems, re-sort again if needed.
+ if(!std::is_sorted(s.begin(), s.end(), StyleRowRangeComp()))
+ std::sort( s.begin(), s.end(), StyleRowRangeComp());
maStylesPerColumn[ rowStyles.first ].insert_sorted_unique_vector( std::move( s ));
}
}