summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_stream.cxx12
-rw-r--r--tools/source/stream/stream.cxx34
2 files changed, 28 insertions, 18 deletions
diff --git a/tools/qa/cppunit/test_stream.cxx b/tools/qa/cppunit/test_stream.cxx
index d8e4d1ef71e1..b58d1f07aaa5 100644
--- a/tools/qa/cppunit/test_stream.cxx
+++ b/tools/qa/cppunit/test_stream.cxx
@@ -84,18 +84,6 @@ 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 f807a56cf52f..0feae91ece83 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -527,6 +527,8 @@ 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();
@@ -819,6 +821,8 @@ 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())
@@ -832,6 +836,8 @@ 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())
@@ -845,6 +851,8 @@ 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())
@@ -858,6 +866,8 @@ 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())
@@ -871,6 +881,8 @@ 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())
@@ -884,14 +896,13 @@ SvStream& SvStream::ReadInt32(sal_Int32& r)
SvStream& SvStream::ReadInt64(sal_Int64& r)
{
+ if (remainingSize() < 8)
+ throw SvStreamEOFException();
sal_Int64 n = 0;
readNumberWithoutSwap(n);
- if (good())
- {
- if (m_isSwap)
- SwapInt64(n);
- r = n;
- }
+ if (m_isSwap)
+ SwapInt64(n);
+ r = n;
return *this;
}
@@ -941,6 +952,8 @@ 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())
@@ -977,6 +990,8 @@ SvStream& SvStream::ReadCharAsBool( bool& r )
SvStream& SvStream::ReadFloat(float& r)
{
+ if (remainingSize() < 4)
+ throw SvStreamEOFException();
float n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -992,6 +1007,8 @@ SvStream& SvStream::ReadFloat(float& r)
SvStream& SvStream::ReadDouble(double& r)
{
+ if (remainingSize() < 8)
+ throw SvStreamEOFException();
double n = 0;
readNumberWithoutSwap(n);
if (good())
@@ -2132,4 +2149,9 @@ 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: */