svx: punish evil-doers who put duplicate properties into custom shapes
LO 4.3.2.2 is evidently able to export an ODF document that violates
XML Well-formedness constraint: Unique Att Spec.
<draw:enhanced-geometry
draw:mirror-horizontal="false"
draw:mirror-vertical="false"
svg:viewBox="0 0 21679 2134682997"
draw:text-areas="0 0 ?f3 ?f2"
draw:mirror-vertical="true"
draw:type="ooxml-rect"
draw:enhanced-path="M 0 0 L ?f3 0 ?f3 ?f2 0 ?f2 Z N">
Not sure how to reproduce this, but the attributes there are apparently a
serialization of SdrCustomShapeGeometryItem's aPropSeq,
retrieved from a "CustomShapeGeometry" property, so add some input
validation and assertions there.
Change-Id: I91151365b507779a4bdc9cce2057d34f2376f005
diff --git a/svx/source/items/customshapeitem.cxx b/svx/source/items/customshapeitem.cxx
index eae790d..cb6e1fa 100644
--- a/svx/source/items/customshapeitem.cxx
+++ b/svx/source/items/customshapeitem.cxx
@@ -46,7 +46,14 @@ SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< bea
for ( i = 0; i < aPropSeq.getLength(); i++ )
{
beans::PropertyValue& rPropVal = aPropSeq[ i ];
aPropHashMap[ rPropVal.Name ] = i;
std::pair<PropertyHashMap::iterator, bool> const ret(
aPropHashMap.insert(std::make_pair(rPropVal.Name, i)));
assert(ret.second); // serious bug: duplicate xml attribute exported
if (!ret.second)
{
throw uno::RuntimeException(
"CustomShapeGeometry has duplicate property " + rPropVal.Name);
}
if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
{
uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
@@ -148,6 +155,9 @@ void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::
}
else
{ // it's a new property
assert(aPropSeq.end() == std::find_if(aPropSeq.begin(), aPropSeq.end(),
[&rPropVal](beans::PropertyValue const& rVal)
{ return rVal.Name == rPropVal.Name; } ));
sal_uInt32 nIndex = aPropSeq.getLength();
aPropSeq.realloc( nIndex + 1 );
aPropSeq[ nIndex ] = rPropVal ;
@@ -171,6 +181,9 @@ void SdrCustomShapeGeometryItem::SetPropertyValue( const OUString& rSequenceName
aValue.Name = rSequenceName;
aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
assert(aPropSeq.end() == std::find_if(aPropSeq.begin(), aPropSeq.end(),
[&rSequenceName](beans::PropertyValue const& rV)
{ return rV.Name == rSequenceName; } ));
sal_uInt32 nIndex = aPropSeq.getLength();
aPropSeq.realloc( nIndex + 1 );
aPropSeq[ nIndex ] = aValue;
@@ -316,7 +329,23 @@ bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMe
if ( ! ( rVal >>= aPropSeq ) )
return false;
else
{
for (sal_Int32 i = 0; i < aPropSeq.getLength(); ++i)
{
for (sal_Int32 j = i+1; j < aPropSeq.getLength(); ++j)
{
if (aPropSeq[i].Name == aPropSeq[j].Name)
{
assert(0); // serious bug: duplicate xml attribute exported
OUString const name(aPropSeq[i].Name);
aPropSeq.realloc(0);
throw uno::RuntimeException(
"CustomShapeGeometry has duplicate property " + name);
}
}
}
return true;
}
}
SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()