summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-01-18 16:19:10 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-01-20 16:20:25 +0100
commit4e639c37b4dcdc27d46111d0d0cbca966544c2cb (patch)
treee2ba04b8df148d863a2c2ab6a4410f297aed47b9 /tools
parentab85732e1c6a1b52cf95fd9fb50b9ccb7cac2137 (diff)
ofz#29691 revert throw SvStreamEOFException
reasonably sane code like s.ReadUInt32(a).ReadUInt32(b).ReadUInt32(c).ReadUInt32(d); if (s.good()) // use a, b, c d; stopped working. FWIW on a short read we retain whatever was in the variable before the read, rather than overwrite it with new random data, so sal_uInt32 a(0xdead); s.ReadUInt32(a); assert(s.good() || a == 0xdead); the msoffice ppt/escher/xls/doc filters especially speculatively parse and rely on a variables preinit value in the case of a short read. commit b345a2bab0d6f981049951a86b172ce49ce7d4c2 cid#1470786 Uncaught exception commit 71aec4726a94dcde1169fd293dbecfeb0e840e6d ofz#29528 uncaught exception commit bed03603f6cae264abb9e5b58aa2ab00448d92ff ofz#29414 uncaught exception commit 684885a99a1eb7ad943e9736166d4bb1468663be ofz#29443 uncaught exception commit 93574ac7768d247ed754ecda322e54e4bd447e43 ofz#29251 Abrt commit 413db68d95bd39d34e6a6b81a7c5c9478ced0514 ofz#29152 short read commit f400e883044143f999c460375a293647b4a57244 ofz#29151 short read commit 96ea80a725dfe4ef38993f78917c243f13e3beb5 ofz#29129 Abrt on uncaught exception commit 646a635efe6eecbc3d1dd3a7cbb02a278c6f3be5 ofz#28931 Indirect-leak commit b0e573f18629d28fe3179c12d0d434653f92fc93 ofz#29030 Abrt in xlsfuzzer commit 95407c39168d186ee44e67b1a6a4bcf592c58b84 ofz#28902 uncaught exception commit 45175d655ad3773df1c006182108cf25e87b1091 oss-fuzz: tgafuzzer doesn't pass sanity check commit b82fc702bae9d6190bda1b4818a47cfa197df6d8 oss-fuzz: psdfuzzer doesn't pass sanity check commit e7c76d604a4694e6568bf10c2a06a786f1096319 oss-fuzz: epsfuzzer doesn't pass sanity check commit 901e5e7c9170184e286ea3e46fce406136aa9572 oss-fuzz: xlsfuzzer doesn't pass sanity check commit 127bfab61c297df06fd8e71e709bc4362cb89d21 oss-fuzz: pngfuzzer doesn't pass sanity check commit 77387ae00ae27e3f8bcdf7bccf97fb2db8f196b7 oss-fuzz: mtpfuzzer doesn't pass sanity check commit 974ffa79b0fef4ca76558bb8b16bce84af3aaf6c oss-fuzz: xlsxfuzzer doesn't pass sanity check commit 6d6d104cbb382d0045e1f04b12d268992fa5c624 oss-fuzz: bmpfuzzer doesn't pass sanity check commit a7d1d107ec58d3b00b4019c89edddcff71ca6ff3 oss-fuzz: qpwfuzzer doesn't pass sanity check commit 898993aa62276f59480df8af1da4bad530829b56 oss-fuzz: pcxfuzzer doesn't pass sanity check throw/catch parts of commit 8c9a4ff511a3b1d84a7a6d08a1b153c07f164abb throw exception in SvStream when reading past end of file Change-Id: Ic49c249768b17b64d8e868655dbc05b31906c2e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109621 Tested-by: Jenkins Tested-by: Caolán McNamara <caolanm@redhat.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_stream.cxx12
-rw-r--r--tools/source/stream/stream.cxx34
2 files changed, 18 insertions, 28 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx
index b58d1f07aaa5..d8e4d1ef71e1 100644
--- a/tools/qa/cppunit/test_stream.cxx
+++ b/tools/qa/cppunit/test_stream.cxx
@@ -84,6 +84,18 @@ namespace
//yet, the read didn't succeed
CPPUNIT_ASSERT(!aMemStream.good());
+ //set things up so that there is only one byte available on an attempt
+ //to read a two-byte sal_uInt16. The byte should be consumed, but the
+ //operation should fail, and tools_b should remain unchanged,
+ sal_uInt16 tools_b = 0x1122;
+ aMemStream.SeekRel(-1);
+ CPPUNIT_ASSERT(!aMemStream.eof());
+ CPPUNIT_ASSERT(aMemStream.good());
+ aMemStream.ReadUInt16( tools_b );
+ CPPUNIT_ASSERT(!aMemStream.good());
+ CPPUNIT_ASSERT(aMemStream.eof());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(0x1122), tools_b);
+
iss.clear();
iss.seekg(0);
CPPUNIT_ASSERT(iss.good());
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 0feae91ece83..f807a56cf52f 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -527,8 +527,6 @@ bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead )
bool SvStream::ReadUniStringLine( OUString& rStr, sal_Int32 nMaxCodepointsToRead )
{
- if (!good())
- throw SvStreamEOFException();
sal_Unicode buf[256+1];
bool bEnd = false;
sal_uInt64 nOldFilePos = Tell();
@@ -821,8 +819,6 @@ sal_uInt64 SvStream::SeekRel(sal_Int64 const nPos)
SvStream& SvStream::ReadUInt16(sal_uInt16& r)
{
- if (remainingSize() < 2)
- throw SvStreamEOFException();
sal_uInt16 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -836,8 +832,6 @@ SvStream& SvStream::ReadUInt16(sal_uInt16& r)
SvStream& SvStream::ReadUInt32(sal_uInt32& r)
{
- if (remainingSize() < 4)
- throw SvStreamEOFException();
sal_uInt32 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -851,8 +845,6 @@ SvStream& SvStream::ReadUInt32(sal_uInt32& r)
SvStream& SvStream::ReadUInt64(sal_uInt64& r)
{
- if (remainingSize() < 8)
- throw SvStreamEOFException();
sal_uInt64 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -866,8 +858,6 @@ SvStream& SvStream::ReadUInt64(sal_uInt64& r)
SvStream& SvStream::ReadInt16(sal_Int16& r)
{
- if (remainingSize() < 2)
- throw SvStreamEOFException();
sal_Int16 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -881,8 +871,6 @@ SvStream& SvStream::ReadInt16(sal_Int16& r)
SvStream& SvStream::ReadInt32(sal_Int32& r)
{
- if (remainingSize() < 4)
- throw SvStreamEOFException();
sal_Int32 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -896,13 +884,14 @@ SvStream& SvStream::ReadInt32(sal_Int32& r)
SvStream& SvStream::ReadInt64(sal_Int64& r)
{
- if (remainingSize() < 8)
- throw SvStreamEOFException();
sal_Int64 n = 0;
readNumberWithoutSwap(n);
- if (m_isSwap)
- SwapInt64(n);
- r = n;
+ if (good())
+ {
+ if (m_isSwap)
+ SwapInt64(n);
+ r = n;
+ }
return *this;
}
@@ -952,8 +941,6 @@ SvStream& SvStream::ReadUChar( unsigned char& r )
SvStream& SvStream::ReadUtf16(sal_Unicode& r)
{
- if (remainingSize() < 2)
- throw SvStreamEOFException();
sal_uInt16 n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -990,8 +977,6 @@ SvStream& SvStream::ReadCharAsBool( bool& r )
SvStream& SvStream::ReadFloat(float& r)
{
- if (remainingSize() < 4)
- throw SvStreamEOFException();
float n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -1007,8 +992,6 @@ SvStream& SvStream::ReadFloat(float& r)
SvStream& SvStream::ReadDouble(double& r)
{
- if (remainingSize() < 8)
- throw SvStreamEOFException();
double n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -2149,9 +2132,4 @@ std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream& rStrm,
return nWritten;
}
-const char * SvStreamEOFException::what() const throw()
-{
- return "SvStreamEOFException";
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */