You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2021/06/26 07:47:33 UTC

[openoffice] branch AOO41X updated (6dff1d4 -> 89f78bf)

This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a change to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git.


    from 6dff1d4  Issue 97058 - Add Fontwork into Insert menu (#15)
     new efddaef  add useful checks
     new 89f78bf  Allow more data than necessary

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 main/connectivity/source/drivers/dbase/DTable.cxx | 91 +++++++++++++++++------
 1 file changed, 67 insertions(+), 24 deletions(-)

[openoffice] 02/02: Allow more data than necessary

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 89f78bf2f1627bd77c8f4bfb01a7f46c6f6a13ad
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Thu May 20 22:13:58 2021 +0200

    Allow more data than necessary
    
    Also translate some comments from German
---
 main/connectivity/source/drivers/dbase/DTable.cxx | 70 +++++++++++------------
 1 file changed, 34 insertions(+), 36 deletions(-)

diff --git a/main/connectivity/source/drivers/dbase/DTable.cxx b/main/connectivity/source/drivers/dbase/DTable.cxx
index 8e6dc67..edac509 100644
--- a/main/connectivity/source/drivers/dbase/DTable.cxx
+++ b/main/connectivity/source/drivers/dbase/DTable.cxx
@@ -897,11 +897,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
         {
             sal_Int32 nDate = 0,nTime = 0;
             OSL_ENSURE(nLen == 8, "Invalid length for date field");
-            if (nLen != 8) {
-                return false;
+            if (nLen >= 8) {
+                memcpy(&nDate, pData, 4);
+                memcpy(&nTime, pData+ 4, 4);
             }
-			memcpy(&nDate, pData, 4);
-            memcpy(&nTime, pData+ 4, 4);
             if ( !nDate && !nTime )
             {
                 (_rRow->get())[i]->setNull();
@@ -916,54 +915,56 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
         else if ( DataType::INTEGER == nType )
         {
             OSL_ENSURE(nLen == 4, "Invalid length for integer field");
-            if (nLen != 4) {
-                return false;
+            if (nLen >= 4) {
+                sal_Int32 nValue = 0;
+                memcpy(&nValue, pData, 4);
+                *(_rRow->get())[i] = nValue;
+            } else {
+                (_rRow->get())[i]->setNull();
             }
-            sal_Int32 nValue = 0;
-			memcpy(&nValue, pData, nLen);
-            *(_rRow->get())[i] = nValue;
         }
         else if ( DataType::DOUBLE == nType )
         {
             double d = 0.0;
             OSL_ENSURE(nLen == 8, "Invalid length for double field");
-            if (nLen != 8) {
-                return false;
-            }
-            if (getBOOL((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt
-            {
-                sal_Int64 nValue = 0;
-			    memcpy(&nValue, pData, nLen);
+            if (nLen >= 8) {
+                if (getBOOL((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency needs special treatment
+                    {
+                        sal_Int64 nValue = 0;
+                        memcpy(&nValue, pData, nLen);
             
-                if ( m_aScales[i-1] )
-                    d = (double)(nValue / pow(10.0,(int)m_aScales[i-1]));
+                        if ( m_aScales[i-1] )
+                            d = (double)(nValue / pow(10.0,(int)m_aScales[i-1]));
+                        else
+                            d = (double)(nValue);
+                    }
                 else
-                    d = (double)(nValue);
-            }
-            else
-            {
-                memcpy(&d, pData, nLen);
-            }
+                    {
+                        memcpy(&d, pData, nLen);
+                    }
             
-            *(_rRow->get())[i] = d;
+                *(_rRow->get())[i] = d;
+            } else {
+                (_rRow->get())[i]->setNull();
+            }
         }
 		else
 		{
-			// Falls Nul-Zeichen im String enthalten sind, in Blanks umwandeln!
+			// Change any nulls into spaces
 			for (sal_Int32 k = 0; k < nLen; k++)
 			{
 				if (pData[k] == '\0')
 					pData[k] = ' ';
 			}
 
-			String aStr(pData, (xub_StrLen)nLen,m_eEncoding);		// Spaces am Anfang und am Ende entfernen:
+			String aStr(pData, (xub_StrLen)nLen,m_eEncoding);		// Strip spaces from beginning and end
 			aStr.EraseLeadingChars();
 			aStr.EraseTrailingChars();
 
 			if (!aStr.Len())
 			{
 				nByteOffset += nLen;
-				(_rRow->get())[i]->setNull();	// keine Werte -> fertig
+				(_rRow->get())[i]->setNull();	// no value -> we are done
 				continue;
 			}
 
@@ -972,11 +973,7 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
 				case DataType::DATE:
 				{
                     OSL_ENSURE(nLen == 8, "Invalid length for date field");
-                    if (nLen != 8) {
-                        return false;
-                    }
-					if (aStr.Len() != nLen)
-					{
+					if ((nLen < 8) || (aStr.Len() != nLen)) {
 						(_rRow->get())[i]->setNull();
 						break;
 					}
@@ -995,8 +992,9 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
 				case DataType::BIT:
 				{
                     OSL_ENSURE(nLen == 1, "Invalid length for bit field");
-                    if (nLen != 1) {
-                        return false;
+                    if (nLen < 1) {
+						(_rRow->get())[i]->setNull();
+						break;
                     }
 					sal_Bool b;
 					switch (* ((const char *)pData))
@@ -1024,7 +1022,7 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
 						(_rRow->get())[i]->setNull();
 				}	break;
 				default:
-					OSL_ASSERT("Falscher Type");
+					OSL_ASSERT("Wrong type");
 			}
 			(_rRow->get())[i]->setTypeKind(nType);
 		}

[openoffice] 01/02: add useful checks

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit efddaef0151af3be16078cc4d88c6bae0f911e56
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sat May 15 21:27:35 2021 +0200

    add useful checks
---
 main/connectivity/source/drivers/dbase/DTable.cxx | 45 +++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/main/connectivity/source/drivers/dbase/DTable.cxx b/main/connectivity/source/drivers/dbase/DTable.cxx
index 2400e8f..8e6dc67 100644
--- a/main/connectivity/source/drivers/dbase/DTable.cxx
+++ b/main/connectivity/source/drivers/dbase/DTable.cxx
@@ -896,6 +896,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
         else if ( DataType::TIMESTAMP == nType )
         {
             sal_Int32 nDate = 0,nTime = 0;
+            OSL_ENSURE(nLen == 8, "Invalid length for date field");
+            if (nLen != 8) {
+                return false;
+            }
 			memcpy(&nDate, pData, 4);
             memcpy(&nTime, pData+ 4, 4);
             if ( !nDate && !nTime )
@@ -911,6 +915,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
         }
         else if ( DataType::INTEGER == nType )
         {
+            OSL_ENSURE(nLen == 4, "Invalid length for integer field");
+            if (nLen != 4) {
+                return false;
+            }
             sal_Int32 nValue = 0;
 			memcpy(&nValue, pData, nLen);
             *(_rRow->get())[i] = nValue;
@@ -918,6 +926,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
         else if ( DataType::DOUBLE == nType )
         {
             double d = 0.0;
+            OSL_ENSURE(nLen == 8, "Invalid length for double field");
+            if (nLen != 8) {
+                return false;
+            }
             if (getBOOL((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency wird gesondert behandelt
             {
                 sal_Int64 nValue = 0;
@@ -959,6 +971,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
 			{
 				case DataType::DATE:
 				{
+                    OSL_ENSURE(nLen == 8, "Invalid length for date field");
+                    if (nLen != 8) {
+                        return false;
+                    }
 					if (aStr.Len() != nLen)
 					{
 						(_rRow->get())[i]->setNull();
@@ -978,6 +994,10 @@ sal_Bool ODbaseTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols, s
 				break;
 				case DataType::BIT:
 				{
+                    OSL_ENSURE(nLen == 1, "Invalid length for bit field");
+                    if (nLen != 1) {
+                        return false;
+                    }
 					sal_Bool b;
 					switch (* ((const char *)pData))
 					{
@@ -1873,6 +1893,11 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c
 			{
                 case DataType::TIMESTAMP:
                     {
+                        OSL_ENSURE(nLen == 8, "Invalid length for timestamp field");
+                        if (nLen != 8) {
+                            bHadError = true;
+                            break;
+                        }
                         sal_Int32 nJulianDate = 0, nJulianTime = 0;
                         lcl_CalcJulDate(nJulianDate,nJulianTime,rRow.get()[nPos]->getValue());
                         // Genau 8 Byte kopieren:
@@ -1882,6 +1907,11 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c
                     break;
 				case DataType::DATE:
 				{
+                    OSL_ENSURE(nLen == 8, "Invalid length for date field");
+                    if (nLen != 8) {
+                        bHadError = true;
+                        break;
+                    }
 					::com::sun::star::util::Date aDate;
 					if(rRow.get()[nPos]->getValue().getTypeKind() == DataType::DOUBLE)
 						aDate = ::dbtools::DBTypeConversion::toDate(rRow.get()[nPos]->getValue().getDouble());
@@ -1900,12 +1930,22 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c
 				} break;
                 case DataType::INTEGER:
                     {
+                        OSL_ENSURE(nLen == 4, "Invalid length for integer field");
+                        if (nLen != 4) {
+                            bHadError = true;
+                            break;
+                        }
                         sal_Int32 nValue = rRow.get()[nPos]->getValue();
                         memcpy(pData,&nValue,nLen);
                     }
                     break;
                 case DataType::DOUBLE:
                     {
+                        OSL_ENSURE(nLen == 8, "Invalid length for double field");
+                        if (nLen != 8) {
+                            bHadError = true;
+                            break;
+                        }
                         const double d = rRow.get()[nPos]->getValue();
                         m_pColumns->getByIndex(i) >>= xCol;
                         
@@ -1958,6 +1998,11 @@ sal_Bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, OValueRefRow pOrgRow,c
 					}
 				} break;
 				case DataType::BIT:
+                    OSL_ENSURE(nLen == 1, "Invalid length for bit field");
+                    if (nLen != 1) {
+                        bHadError = true;
+                        break;
+                    }
 					*pData = rRow.get()[nPos]->getValue().getBool() ? 'T' : 'F';
 					break;
                 case DataType::LONGVARBINARY: