[Libreoffice-commits] libmspub.git: src/lib
David Tardon
dtardon at redhat.com
Fri May 10 23:51:28 PDT 2013
src/lib/Fill.cpp | 4 ++--
src/lib/MSPUBCollector.cpp | 13 ++++++++++---
src/lib/MSPUBParser.cpp | 4 ++--
3 files changed, 14 insertions(+), 7 deletions(-)
New commits:
commit 95af3103bfed35a3aafe683b4fc33c761a2959c9
Author: David Tardon <dtardon at redhat.com>
Date: Sat May 11 08:50:40 2013 +0200
avoid more vector index underflows
diff --git a/src/lib/Fill.cpp b/src/lib/Fill.cpp
index f563517..d9202c4 100644
--- a/src/lib/Fill.cpp
+++ b/src/lib/Fill.cpp
@@ -44,7 +44,7 @@ ImgFill::ImgFill(unsigned imgIndex, const MSPUBCollector *owner, bool isTexture,
WPXPropertyListVector ImgFill::getProperties(WPXPropertyList *out) const
{
out->insert("draw:fill", "bitmap");
- if (m_imgIndex <= m_owner->m_images.size())
+ if (m_imgIndex > 0 && m_imgIndex <= m_owner->m_images.size())
{
const std::pair<ImgType, WPXBinaryData> &img = m_owner->m_images[m_imgIndex - 1];
out->insert("libwpg:mime-type", mimeByImgType(img.first));
@@ -73,7 +73,7 @@ WPXPropertyListVector PatternFill::getProperties(WPXPropertyList *out) const
Color fgColor = m_fg.getFinalColor(m_owner->m_paletteColors);
Color bgColor = m_bg.getFinalColor(m_owner->m_paletteColors);
out->insert("draw:fill", "bitmap");
- if (m_imgIndex <= m_owner->m_images.size())
+ if (m_imgIndex > 0 && m_imgIndex <= m_owner->m_images.size())
{
const std::pair<ImgType, WPXBinaryData> &img = m_owner->m_images[m_imgIndex - 1];
const ImgType &type = img.first;
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp
index b863b50..b8a96a9 100644
--- a/src/lib/MSPUBCollector.cpp
+++ b/src/lib/MSPUBCollector.cpp
@@ -1502,13 +1502,20 @@ void libmspub::MSPUBCollector::setHeightInEmu(unsigned long heightInEmu)
bool libmspub::MSPUBCollector::addImage(unsigned index, ImgType type, WPXBinaryData img)
{
- MSPUB_DEBUG_MSG(("Image at index %d and of type 0x%x added.\n", index, type));
while (m_images.size() < index)
{
m_images.push_back(std::pair<ImgType, WPXBinaryData>(UNKNOWN, WPXBinaryData()));
}
- m_images[index - 1] = std::pair<ImgType, WPXBinaryData>(type, img);
- return true;
+ if (index > 0)
+ {
+ MSPUB_DEBUG_MSG(("Image at index %d and of type 0x%x added.\n", index, type));
+ m_images[index - 1] = std::pair<ImgType, WPXBinaryData>(type, img);
+ }
+ else
+ {
+ MSPUB_DEBUG_MSG(("0 is not a valid index for image, ignoring.\n"));
+ }
+ return index > 0;
}
WPXBinaryData *libmspub::MSPUBCollector::addBorderImage(ImgType type,
diff --git a/src/lib/MSPUBParser.cpp b/src/lib/MSPUBParser.cpp
index 4d1e2ca..72f637e 100644
--- a/src/lib/MSPUBParser.cpp
+++ b/src/lib/MSPUBParser.cpp
@@ -1991,7 +1991,7 @@ boost::shared_ptr<libmspub::Fill> libmspub::MSPUBParser::getNewFill(const std::m
if (ptr_rotation)
rotation = (int)doubleModulo(toFixedPoint(*ptr_rotation), 360);
const unsigned *ptr_bgPxId = getIfExists_const(foptProperties, FIELDID_BG_PXID);
- if (ptr_bgPxId && *ptr_bgPxId <= m_escherDelayIndices.size() && m_escherDelayIndices[*ptr_bgPxId - 1] >= 0)
+ if (ptr_bgPxId && *ptr_bgPxId > 0 && *ptr_bgPxId <= m_escherDelayIndices.size() && m_escherDelayIndices[*ptr_bgPxId - 1] >= 0)
{
return boost::shared_ptr<Fill>(new ImgFill(m_escherDelayIndices[*ptr_bgPxId - 1], m_collector, fillType == TEXTURE, rotation));
}
@@ -2005,7 +2005,7 @@ boost::shared_ptr<libmspub::Fill> libmspub::MSPUBParser::getNewFill(const std::m
ColorReference fill = ptr_fillColor ? ColorReference(*ptr_fillColor) : ColorReference(0x00FFFFFF);
// ColorReference back = ptr_fillBackColor ? ColorReference(*ptr_fillBackColor) : ColorReference(0x08000000);
ColorReference back = ptr_fillBackColor ? ColorReference(*ptr_fillBackColor) : ColorReference(0x00FFFFFF);
- if (ptr_bgPxId && *ptr_bgPxId <= m_escherDelayIndices.size() && m_escherDelayIndices[*ptr_bgPxId - 1 ] >= 0)
+ if (ptr_bgPxId && *ptr_bgPxId > 0 && *ptr_bgPxId <= m_escherDelayIndices.size() && m_escherDelayIndices[*ptr_bgPxId - 1] >= 0)
{
return boost::shared_ptr<Fill>(new PatternFill(m_escherDelayIndices[*ptr_bgPxId - 1], m_collector, fill, back));
}
More information about the Libreoffice-commits
mailing list