Merge pull request #3 from cinecert/master
authorWolfgang Ruppel <imftool@t-online.de>
Sat, 6 Jul 2019 13:56:43 +0000 (15:56 +0200)
committerGitHub <noreply@github.com>
Sat, 6 Jul 2019 13:56:43 +0000 (15:56 +0200)
Sync with upstream

configure.ac
src/AS_02_ISXD.cpp
src/AS_DCP_internal.h
src/KM_fileio.cpp
src/KM_log.cpp
src/MXF.cpp
src/h__02_Reader.cpp
src/h__Reader.cpp

index 74e3f317c5c1136f0885938a45212f6ae18dc8f4..d4a74593445dee9fd7ee09f3d8b135d6d1759f8e 100644 (file)
@@ -37,7 +37,7 @@ AC_PREREQ([2.59])
 # For example, if asdcplib version 1.0.0 were modified to accomodate changes
 # in file format, and if no changes were made to AS_DCP.h, the new version would be
 # 1.0.1. If changes were also required in AS_DCP.h, the new version would be 1.1.1.
-AC_INIT([asdcplib], [2.10.33], [asdcplib@cinecert.com])
+AC_INIT([asdcplib], [2.10.34], [asdcplib@cinecert.com])
 
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_SRCDIR([src/KM_error.h])
index f4e29c07ff592fc3b3100065f2a3a5da48fc0eb6..6230c583045ada4783beadba39b7d8bb38fa5d8e 100644 (file)
@@ -319,7 +319,7 @@ AS_02::ISXD::MXFWriter::h__Writer::OpenWrite(const std::string& filename, const
   return result;
 }
 
-// Automatically sets the MXF file's metadata from the first jpeg codestream stream.
+// Automatically sets the MXF file's metadata from the first ISXD data fragment stream.
 Result_t
 AS_02::ISXD::MXFWriter::h__Writer::SetSourceStream(const std::string& label, const ASDCP::Rational& edit_rate)
 {
index 83272c09b431a8861ab0a0355abc0172d186d961..57ed006a04dffcee8351ae8362d489e2603a6ba3 100755 (executable)
@@ -414,17 +414,23 @@ namespace ASDCP
          // Count the sequence length in because this is the sequence
          // value needed to  complete the HMAC.
          ASDCP::MXF::RIP::const_pair_iterator i;
-         for ( i = m_RIP.PairArray.begin(); i != m_RIP.PairArray.end(); ++i, ++sequence )
+         for ( i = m_RIP.PairArray.begin(); i != m_RIP.PairArray.end(); ++i)
            {
-             if ( sid == i->BodySID )
-               {
-                 start_offset = i->ByteOffset;
-               }
-             else if ( start_offset != 0 )
-               {
-                 end_offset = i->ByteOffset;
-                 break;
-               }
+              if ( sid == i->BodySID )
+                {
+                  assert( start_offset == 0);
+                  start_offset = i->ByteOffset;
+                }
+              else if ( start_offset != 0 )
+                {
+                  end_offset = i->ByteOffset;
+                  break;
+                }
+
+              if ( i->BodySID > 0 )
+                {
+                  ++sequence;
+                }
            }
 
          if ( start_offset == 0 || end_offset == 0 )
index 07c649fecc91343cb1d8ff0c317a3d5b61a6e54e..27a5bfa01da23fc90918dbc5c4f381c786e74a0f 100644 (file)
@@ -1255,8 +1255,8 @@ Kumu::ReadFileIntoString(const std::string& filename, std::string& outString, ui
 
       if ( fsize == 0 )
        {
-         DefaultLogSink().Error("%s: zero file size\n", filename.c_str());
-         return RESULT_READFAIL;
+         outString = "";
+         return RESULT_OK;
        }
 
       result = ReadBuf.Capacity((ui32_t)fsize);
index 182d91e6ee2cb2730230cc39672e0d5ad8fbd562..d820dba50df002aaf82e652c664d765e829dd386 100755 (executable)
@@ -151,7 +151,8 @@ Kumu::StreamLogSink::WriteEntry(const LogEntry& Entry)
   if ( Entry.TestFilter(m_filter) )
     {
       Entry.CreateStringWithOptions(buf, m_options);
-      write(m_fd, buf.c_str(), buf.size());
+      ssize_t n = write(m_fd, buf.c_str(), buf.size());
+      assert(n==buf.size());
     }
 }
 
index 743cc69ea0ddd4499c7da64a29c6392497eaf3d5..b49fb83b5cfd1e4f18456dcf27279cb63091935f 100755 (executable)
@@ -125,6 +125,11 @@ ASDCP::MXF::RIP::InitFromFile(const Kumu::FileReader& Reader)
 
   if ( ASDCP_SUCCESS(result) )
     {
+      if (m_ValueLength < 4)
+      {
+        DefaultLogSink().Error("RIP is too short.\n");
+        return RESULT_KLV_CODING(__LINE__, __FILE__);
+      }
       Kumu::MemIOReader MemRDR(m_ValueStart, m_ValueLength - 4);
       result = PairArray.Unarchive(&MemRDR) ? RESULT_OK : RESULT_KLV_CODING(__LINE__, __FILE__);
     }
@@ -448,6 +453,11 @@ ASDCP::MXF::Primer::InitFromBuffer(const byte_t* p, ui32_t l)
 
   if ( ASDCP_SUCCESS(result) )
     {
+      if (m_ValueStart + m_ValueLength > p + l)
+      {
+        DefaultLogSink().Error("Primer entry too long.\n");
+        return RESULT_KLV_CODING(__LINE__, __FILE__);
+      }
       Kumu::MemIOReader MemRDR(m_ValueStart, m_ValueLength);
       result = LocalTagEntryBatch.Unarchive(&MemRDR) ? RESULT_OK : RESULT_KLV_CODING(__LINE__, __FILE__);
     }
@@ -1380,6 +1390,12 @@ ASDCP::MXF::InterchangeObject::InitFromBuffer(const byte_t* p, ui32_t l)
 
       if ( ASDCP_SUCCESS(result) )
        {
+         if ( ( m_ValueStart + m_ValueLength ) > ( p  + l ) )
+           {
+             DefaultLogSink().Error("Interchange Object value extends past buffer length.\n");
+             return RESULT_KLV_CODING(__LINE__, __FILE__);
+           }
+
          TLVReader MemRDR(m_ValueStart, m_ValueLength, m_Lookup);
          result = InitFromTLVSet(MemRDR);
        }
@@ -1440,9 +1456,24 @@ ASDCP::MXF::InterchangeObject::IsA(const byte_t* label)
 
 
 //------------------------------------------------------------------------------------------
+struct FactoryCompareUL
+{
+    bool operator()(const ASDCP::UL& lhs, const ASDCP::UL& rhs) const
+    {
+        ui32_t test_size = lhs.Size() < rhs.Size() ? lhs.Size() : rhs.Size();
 
+        for (ui32_t i = 0; i < test_size; i++)
+        {
+            if (i == 7) continue; // skip version to be symmetrical with UL::operator==
+            if (lhs.Value()[i] != rhs.Value()[i])
+                return lhs.Value()[i] < rhs.Value()[i];
+        }
+
+        return false;
+    }
+};
 
-typedef std::map<ASDCP::UL, ASDCP::MXF::MXFObjectFactory_t>FactoryMap_t;
+typedef std::map<ASDCP::UL, ASDCP::MXF::MXFObjectFactory_t, FactoryCompareUL>FactoryMap_t;
 typedef FactoryMap_t::iterator FLi_t;
 
 //
@@ -1503,7 +1534,7 @@ ASDCP::MXF::CreateObject(const Dictionary*& Dict, const UL& label)
        }
     }
 
-  FLi_t i = s_FactoryList.find(label.Value());
+  FLi_t i = s_FactoryList.find(label);
 
   if ( i == s_FactoryList.end() )
     return new InterchangeObject(Dict);
index 17e9b0d78385ce9b93c3d95db490ac5befc3a2b7..b3c092b39ede5b625a55a6ef94b50ca1c180b50a 100644 (file)
@@ -430,10 +430,13 @@ AS_02::h__AS02Reader::OpenMXFRead(const std::string& filename)
        }
 
       //
-      if ( m_RIP.PairArray.front().ByteOffset != 0 )
+      if ( ! m_RIP.PairArray.empty() )
        {
-         DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n");
-         return RESULT_AS02_FORMAT;
+         if ( m_RIP.PairArray.front().ByteOffset != 0 )
+           {
+             DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n");
+             return RESULT_AS02_FORMAT;
+           }
        }
 
       Kumu::fpos_t first_partition_after_header = 0;
index a764767fc99837062595229503fbcf17e98bfc26..77f532e7fe20c1edd6d90a29d37b9ec9f1900c55 100755 (executable)
@@ -108,7 +108,7 @@ ASDCP::h__ASDCPReader::OpenMXFRead(const std::string& filename)
            }
        }
 
-      if ( m_RIP.PairArray.front().ByteOffset != 0 )
+      if ( !m_RIP.PairArray.empty() && m_RIP.PairArray.front().ByteOffset != 0 )
        {
          DefaultLogSink().Error("First Partition in RIP is not at offset 0.\n");
          result = RESULT_FORMAT;