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

reject invalid dbase files with 0 len db_slng right at the start

Change-Id: If4aa5249391ea2d2e475fa3ebaccf4e9fc7442de
üst e7fb96a1
...@@ -214,6 +214,8 @@ void ODbaseTable::readHeader() ...@@ -214,6 +214,8 @@ void ODbaseTable::readHeader()
(*m_pFileStream).ReadUInt16( m_aHeader.db_slng ); (*m_pFileStream).ReadUInt16( m_aHeader.db_slng );
if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
throwInvalidDbaseFormat(); throwInvalidDbaseFormat();
if (m_aHeader.db_slng == 0)
throwInvalidDbaseFormat();
m_pFileStream->Read((char*)(&m_aHeader.db_frei), 20*sizeof(sal_uInt8)); m_pFileStream->Read((char*)(&m_aHeader.db_frei), 20*sizeof(sal_uInt8));
if(ERRCODE_NONE != m_pFileStream->GetErrorCode()) if(ERRCODE_NONE != m_pFileStream->GetErrorCode())
throwInvalidDbaseFormat(); throwInvalidDbaseFormat();
...@@ -1497,9 +1499,9 @@ bool ODbaseTable::DropImpl() ...@@ -1497,9 +1499,9 @@ bool ODbaseTable::DropImpl()
bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference<XIndexAccess>& _xCols) bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference<XIndexAccess>& _xCols)
{ {
// fill buffer with blanks // fill buffer with blanks
AllocBuffer(); if (!AllocBuffer())
if (!m_pBuffer)
return false; return false;
memset(m_pBuffer, 0, m_aHeader.db_slng); memset(m_pBuffer, 0, m_aHeader.db_slng);
m_pBuffer[0] = ' '; m_pBuffer[0] = ' ';
...@@ -1556,7 +1558,8 @@ bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference< ...@@ -1556,7 +1558,8 @@ bool ODbaseTable::InsertRow(OValueRefVector& rRow, bool bFlush, const Reference<
bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow, const Reference<XIndexAccess>& _xCols) bool ODbaseTable::UpdateRow(OValueRefVector& rRow, OValueRefRow& pOrgRow, const Reference<XIndexAccess>& _xCols)
{ {
// fill buffer with blanks // fill buffer with blanks
AllocBuffer(); if (!AllocBuffer())
return false;
// position on desired record: // position on desired record:
sal_Size nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng; sal_Size nPos = m_aHeader.db_kopf + (long)(m_nFilePos-1) * m_aHeader.db_slng;
...@@ -2743,10 +2746,10 @@ bool ODbaseTable::ReadMemo(sal_Size nBlockNo, ORowSetValue& aVariable) ...@@ -2743,10 +2746,10 @@ bool ODbaseTable::ReadMemo(sal_Size nBlockNo, ORowSetValue& aVariable)
return true; return true;
} }
void ODbaseTable::AllocBuffer() bool ODbaseTable::AllocBuffer()
{ {
sal_uInt16 nSize = m_aHeader.db_slng; sal_uInt16 nSize = m_aHeader.db_slng;
OSL_ENSURE(nSize > 0, "Size too small"); SAL_WARN_IF(nSize == 0, "connectivity.drivers", "Size too small");
if (m_nBufferSize != nSize) if (m_nBufferSize != nSize)
{ {
...@@ -2760,6 +2763,8 @@ void ODbaseTable::AllocBuffer() ...@@ -2760,6 +2763,8 @@ void ODbaseTable::AllocBuffer()
m_nBufferSize = nSize; m_nBufferSize = nSize;
m_pBuffer = new sal_uInt8[m_nBufferSize+1]; m_pBuffer = new sal_uInt8[m_nBufferSize+1];
} }
return m_pBuffer != NULL;
} }
bool ODbaseTable::WriteBuffer() bool ODbaseTable::WriteBuffer()
......
...@@ -112,7 +112,7 @@ namespace connectivity ...@@ -112,7 +112,7 @@ namespace connectivity
bool WriteBuffer(); bool WriteBuffer();
bool UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols, bool bForceAllFields); bool UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xCols, bool bForceAllFields);
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos); ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> isUniqueByColumnName(sal_Int32 _nColumnPos);
void AllocBuffer(); bool AllocBuffer();
void throwInvalidDbaseFormat(); void throwInvalidDbaseFormat();
void SAL_CALL renameImpl( const OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); void SAL_CALL renameImpl( const OUString& newName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
......
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