Kaydet (Commit) 575aac6d authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz#5420 Out-of-memory

Change-Id: I22166a14a03e5e803f8f032034e05a2da501379f
Reviewed-on: https://gerrit.libreoffice.org/48008Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 18e9fc8b
......@@ -70,7 +70,8 @@ public:
sal_Int32 Read( void* bytes, sal_Int32 nBytesToRead );
void SeekRel( sal_Int64 pos );
sal_Int64 Tell();
sal_Int64 Seek( sal_Int64 pos );
sal_Int64 Seek(sal_Int64 pos);
bool CheckSeek(sal_Int64 pos);
LwpSvStream& ReadUInt8( sal_uInt8& rUInt8 );
LwpSvStream& ReadUInt16( sal_uInt16& rUInt16 );
......
......@@ -75,20 +75,22 @@ Lwp9Reader::Lwp9Reader (LwpSvStream* pInputStream, IXFStream* pStream)
/**
* @descr The entrance of Word Pro 9 import filter.
**/
void Lwp9Reader::Read()
bool Lwp9Reader::Read()
{
bool bRet = true;
LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance(m_pDocStream);
try
{
m_pObjMgr = pGlobal->GetLwpObjFactory();
ReadFileHeader();
//Does not support Word Pro 96 and previous versions
if(LwpFileHeader::m_nFileRevision>=0x000B)
if (ReadFileHeader() && LwpFileHeader::m_nFileRevision>=0x000B)
{
ReadIndex();
ParseDocument();
bRet = ParseDocument();
}
else
bRet = false;
}
catch(...)
{
......@@ -96,14 +98,16 @@ void Lwp9Reader::Read()
throw;
}
LwpGlobalMgr::DeleteInstance();
return bRet;
}
/**
* @descr Read the LWP7 object.
*/
void Lwp9Reader::ReadFileHeader()
bool Lwp9Reader::ReadFileHeader()
{
m_pDocStream->Seek(LwpSvStream::LWP_STREAM_BASE);
if (!m_pDocStream->CheckSeek(LwpSvStream::LWP_STREAM_BASE))
return false;
//Remember to initialize the LwpFileHeader::m_nFileRevision first.
LwpFileHeader::m_nFileRevision = 0;
......@@ -112,8 +116,7 @@ void Lwp9Reader::ReadFileHeader()
objHdr.Read(*m_pDocStream);
sal_Int64 pos = m_pDocStream->Tell();
m_LwpFileHdr.Read(m_pDocStream);
m_pDocStream->Seek(pos+objHdr.GetSize());
return m_pDocStream->CheckSeek(pos + objHdr.GetSize());
}
/**
......@@ -131,7 +134,7 @@ void Lwp9Reader::ReadIndex()
/**
* @descr Parse all document content
*/
void Lwp9Reader::ParseDocument()
bool Lwp9Reader::ParseDocument()
{
WriteDocHeader();
......@@ -139,7 +142,7 @@ void Lwp9Reader::ParseDocument()
LwpDocument* doc = dynamic_cast<LwpDocument*> ( m_LwpFileHdr.GetDocID().obj().get() );
if (!doc)
return;
return false;
//Parse Doc Data
LwpDocData *pDocData = dynamic_cast<LwpDocData*>(doc->GetDocData().obj().get());
......@@ -165,6 +168,7 @@ void Lwp9Reader::ParseDocument()
m_pStream->EndElement("office:body");
WriteDocEnd();
return true;
}
/**
......
......@@ -74,13 +74,13 @@ private:
IXFStream* m_pStream;
LwpObjectFactory* m_pObjMgr;
LwpFileHeader m_LwpFileHdr; //LWP7 object
void ReadFileHeader();
bool ReadFileHeader();
void ReadIndex();
void ParseDocument();
bool ParseDocument();
void WriteDocHeader();
void WriteDocEnd();
public:
void Read();
bool Read();
};
#endif
......
......@@ -183,6 +183,7 @@ bool Decompress(SvStream *pCompressed, SvStream * & pOutDecompressed)
}
int ReadWordproFile(SvStream &rStream, uno::Reference<css::xml::sax::XDocumentHandler> const & xHandler)
{
int nRet = 0;
try
{
LwpSvStream *pRawLwpSvStream = nullptr;
......@@ -211,13 +212,15 @@ int ReadWordproFile(SvStream &rStream, uno::Reference<css::xml::sax::XDocumentHa
Lwp9Reader reader(aLwpSvStream.get(), pStrm.get());
//Reset all static objects,because this function may be called many times.
XFGlobalReset();
reader.Read();
const bool bOk = reader.Read();
if (!bOk)
nRet = 1;
}
catch (...)
{
return 1;
}
return 0;
return nRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -101,14 +101,19 @@ void LwpSvStream::SeekRel(sal_Int64 pos)
*/
sal_Int64 LwpSvStream::Tell()
{
return m_pStream->Tell();
return m_pStream->Tell();
}
/**
* @descr Seek to pos
*/
sal_Int64 LwpSvStream::Seek(sal_Int64 pos)
{
return m_pStream->Seek(pos);
return m_pStream->Seek(pos);
}
bool LwpSvStream::CheckSeek(sal_Int64 pos)
{
return checkSeek(*m_pStream, pos);
}
/**
* @descr Return the stream data length
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment