diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-06-03 22:53:20 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-06-06 14:49:30 +0200 |
commit | 4849f342b6969abb777d91a1fa77ec120f861c48 (patch) | |
tree | cf919eee7ff89ac614f42f2b809bd9edbeb4261e /connectivity | |
parent | 6325cdb735effc5c9ff85819b20aec4271158519 (diff) |
connectivity: DBase: fix some obvious endian issues
These calls to SvStream::Read/Write operate on structs that contain
32-bit integers.
Change-Id: I2d45128ad482013cd9ef1fca0dd259dfc09c904f
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/dbase/DIndex.cxx | 32 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndexes.cxx | 2 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DTable.cxx | 11 | ||||
-rw-r--r-- | connectivity/source/inc/dbase/DIndex.hxx | 2 |
4 files changed, 42 insertions, 5 deletions
diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index a2e8e3e962b0..0a6e2255cfd2 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -349,11 +349,27 @@ ONDXPage* ODbaseIndex::CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent, bool b return pPage; } +void connectivity::dbase::ReadHeader( + SvStream & rStream, ODbaseIndex::NDXHeader & rHeader) +{ + sal_uInt64 const nOldPos(rStream.Tell()); + rStream.ReadUInt32(rHeader.db_rootpage); + rStream.ReadUInt32(rHeader.db_pagecount); + rStream.Read(&rHeader.db_frei, 4); + rStream.ReadUInt16(rHeader.db_keylen); + rStream.ReadUInt16(rHeader.db_maxkeys); + rStream.ReadUInt16(rHeader.db_keytype); + rStream.ReadUInt16(rHeader.db_keyrec); + rStream.Read(&rHeader.db_frei1, 3); + rStream.ReadUChar(rHeader.db_unique); + rStream.Read(&rHeader.db_name, 488); + assert(rStream.GetError() || rStream.Tell() == nOldPos + DINDEX_PAGE_SIZE); +} SvStream& connectivity::dbase::operator >> (SvStream &rStream, ODbaseIndex& rIndex) { rStream.Seek(0); - rStream.Read(&rIndex.m_aHeader,DINDEX_PAGE_SIZE); + ReadHeader(rStream, rIndex.m_aHeader); rIndex.m_nRootPage = rIndex.m_aHeader.db_rootpage; rIndex.m_nPageCount = rIndex.m_aHeader.db_pagecount; @@ -363,7 +379,19 @@ SvStream& connectivity::dbase::operator >> (SvStream &rStream, ODbaseIndex& rInd SvStream& connectivity::dbase::WriteODbaseIndex(SvStream &rStream, ODbaseIndex& rIndex) { rStream.Seek(0); - OSL_VERIFY( rStream.Write(&rIndex.m_aHeader,DINDEX_PAGE_SIZE) == DINDEX_PAGE_SIZE ); + sal_uInt64 const nOldPos(rStream.Tell()); + rStream.WriteUInt32(rIndex.m_aHeader.db_rootpage); + rStream.WriteUInt32(rIndex.m_aHeader.db_pagecount); + rStream.Write(&rIndex.m_aHeader.db_frei, 4); + rStream.WriteUInt16(rIndex.m_aHeader.db_keylen); + rStream.WriteUInt16(rIndex.m_aHeader.db_maxkeys); + rStream.WriteUInt16(rIndex.m_aHeader.db_keytype); + rStream.WriteUInt16(rIndex.m_aHeader.db_keyrec); + rStream.Write(&rIndex.m_aHeader.db_frei1, 3); + rStream.WriteUChar(rIndex.m_aHeader.db_unique); + rStream.Write(&rIndex.m_aHeader.db_name, 488); + assert(rStream.GetError() || rStream.Tell() == nOldPos + DINDEX_PAGE_SIZE); + SAL_WARN_IF(rStream.GetError(), "connectivity.dbase", "write error"); return rStream; } diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx index 939fd8a2a0a5..34e98ec25e9b 100644 --- a/connectivity/source/drivers/dbase/DIndexes.cxx +++ b/connectivity/source/drivers/dbase/DIndexes.cxx @@ -60,7 +60,7 @@ sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) ODbaseIndex::NDXHeader aHeader; pFileStream->Seek(0); - pFileStream->Read(&aHeader,DINDEX_PAGE_SIZE); + ReadHeader(*pFileStream, aHeader); delete pFileStream; ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index e3d518c80f03..95c65ca73825 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -323,8 +323,15 @@ void ODbaseTable::fillColumns() for (; i < nFieldCount; i++) { DBFColumn aDBFColumn; - sal_Size nRead = m_pFileStream->Read(&aDBFColumn, sizeof(aDBFColumn)); - if (nRead != sizeof(aDBFColumn)) + sal_uInt64 const nOldPos(m_pFileStream->Tell()); + m_pFileStream->Read(aDBFColumn.db_fnm, 11); + m_pFileStream->ReadUChar(aDBFColumn.db_typ); + m_pFileStream->ReadUInt32(aDBFColumn.db_adr); + m_pFileStream->ReadUChar(aDBFColumn.db_flng); + m_pFileStream->ReadUChar(aDBFColumn.db_dez); + m_pFileStream->Read(aDBFColumn.db_frei2, 14); + assert(m_pFileStream->GetError() || m_pFileStream->Tell() == nOldPos + sizeof(aDBFColumn)); + if (m_pFileStream->GetError()) { SAL_WARN("connectivity.drivers", "ODbaseTable::fillColumns: short read!"); break; diff --git a/connectivity/source/inc/dbase/DIndex.hxx b/connectivity/source/inc/dbase/DIndex.hxx index 3b51c11bd49b..b7f40ffcbc05 100644 --- a/connectivity/source/inc/dbase/DIndex.hxx +++ b/connectivity/source/inc/dbase/DIndex.hxx @@ -139,6 +139,8 @@ namespace connectivity SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&); SvStream& operator >> (SvStream &rStream, ODbaseIndex&); + + void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader); } } |