]> OCCT Git - occt-copy.git/commitdiff
0031513: Data Exchange - FSD_Base64Decoder::Decode() returns buffer with wrong length
authorkgv <kgv@opencascade.com>
Wed, 22 Apr 2020 20:50:55 +0000 (23:50 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Sep 2020 14:46:58 +0000 (17:46 +0300)
src/FSD/FSD_Base64Decoder.cxx

index 21bc88d8aba073dc0f6175f14fedfc3d7acb979a..f51ec5bb30ebfb64bd150f90715c882ccfca35b2 100644 (file)
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
 
+//! Buffer with decoded data.
+class FSD_Base64DecoderBuffer : public NCollection_Buffer
+{
+public:
+  //! Empty constructor.
+  FSD_Base64DecoderBuffer() : NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator()) {}
+
+  //! Shrink data size.
+  void ShrinkSize (Standard_Size theSize)
+  {
+    if (theSize < mySize)
+    {
+      mySize = theSize;
+    }
+  }
+};
+
 // =======================================================================
 // function : Decode
 // purpose  :
@@ -37,7 +54,7 @@ Handle(NCollection_Buffer) FSD_Base64Decoder::Decode (const Standard_Byte* theSt
     41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51, 255, 255, 255, 255, 255
   };
 
-  Handle(NCollection_Buffer) aData = new NCollection_Buffer (NCollection_BaseAllocator::CommonBaseAllocator());
+  Handle(FSD_Base64DecoderBuffer) aData = new FSD_Base64DecoderBuffer();
   if (!aData->Allocate (3 * theLen / 4))
   {
     Message::SendFail ("Fail to allocate memory.");
@@ -82,6 +99,8 @@ Handle(NCollection_Buffer) FSD_Base64Decoder::Decode (const Standard_Byte* theSt
       ++aDataPtr;
     }
   }
-
+  // shrink buffer size to actual length
+  const Standard_Size aFinalLen = aDataPtr - aData->ChangeData();
+  aData->ShrinkSize (aFinalLen);
   return aData;
 }