src/lib/CDRDocument.cpp        |   49 ++++++++++++++++-------------------------
 src/lib/CDRParser.cpp          |   18 ++++++++++-----
 src/lib/CDRStylesCollector.cpp |    2 -
 src/lib/CMXParser.cpp          |    2 -
 src/lib/libcdr_utils.cpp       |    4 +--
 src/lib/libcdr_utils.h         |   11 +++++----
 6 files changed, 43 insertions(+), 43 deletions(-)

New commits:
commit eb0a026e89d129919c32f5412d72c794c0d1f20f
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun Nov 15 21:29:24 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun Nov 15 21:29:24 2026 +0000

    cid#1708421 Variable copied when it could be moved
    
    and
    
    cid#1708422 Variable copied when it could be moved
    cid#1708423 Variable copied when it could be moved
    cid#1708424 Variable copied when it could be moved
    cid#1708427 Variable copied when it could be moved
    cid#1708429 Variable copied when it could be moved
    cid#1708430 Variable copied when it could be moved
    cid#1708431 Variable copied when it could be moved
    cid#1708432 Variable copied when it could be moved
    cid#1708433 Variable copied when it could be moved
    cid#1708436 Variable copied when it could be moved
    
    appendCharacters never changes its vector, so take it by const reference
    
    Change-Id: I15b71710e472fdfff312f020abbea7053b8922f2

diff --git a/src/lib/CDRDocument.cpp b/src/lib/CDRDocument.cpp
index ae065bb..f0c0f50 100644
--- a/src/lib/CDRDocument.cpp
+++ b/src/lib/CDRDocument.cpp
@@ -165,7 +165,7 @@ CDRAPI bool 
libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input_, libr
                 dataFileName += (char)character;
             }
             if (!dataFileName.empty())
-              dataFiles.push_back(dataFileName);
+              dataFiles.push_back(std::move(dataFileName));
           }
         }
       }
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index cde7bde..1baf121 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -284,7 +284,7 @@ void readFittedPlaces(librevenge::RVNGInputStream *input, 
std::vector<unsigned c
     style.m_shiftY = shiftY / 100.0;
     style.m_rotation = rotation / 1000000.0;
     unsigned key = firstKey + 2 * (unsigned)i;
-    styles[key] = style;
+    styles[key] = std::move(style);
     charDescriptions[i] = (unsigned char)(key | (charDescriptions[i] & 0x01));
   }
   // left aligned: the places are from the text's origin, its placement on the 
path in them
@@ -2899,7 +2899,7 @@ void 
libcdr::CDRParser::readTxsm(librevenge::RVNGInputStream *input, unsigned le
               input->seek(48, librevenge::RVNG_SEEK_CUR);
           }
         }
-        styles[2*i] = style;
+        styles[2*i] = std::move(style);
       }
       unsigned long numChars = readU32(input);
       const unsigned charSize = m_version >= 1200 ? 8 : 4;
@@ -3152,7 +3152,7 @@ void 
libcdr::CDRParser::readTxsm6(librevenge::RVNGInputStream *input)
         if (iter != m_lineStyles.end())
           style.m_lineStyle = iter->second;
       }
-      styles[2*i] = style;
+      styles[2*i] = std::move(style);
     }
     unsigned numChars = readU32(input);
     input->seek(4, librevenge::RVNG_SEEK_CUR);
@@ -3262,7 +3262,7 @@ void 
libcdr::CDRParser::readTxsm5(librevenge::RVNGInputStream *input)
       if (flag&0x80)
         style.m_shiftY = shiftY / 100.0;
       input->seek(10, librevenge::RVNG_SEEK_CUR);
-      styles[2*i] = style;
+      styles[2*i] = std::move(style);
     }
     unsigned long numChars = readU16(input);
     if (numChars > getRemainingLength(input) / 8)
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 39866c9..9ea543a 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -330,7 +330,7 @@ void libcdr::CDRStylesCollector::collectText(unsigned 
textId, unsigned styleId,
   tmpCharStyle = styleOf(tmpKey);
   if (!i)   // an empty paragraph: its style all the same (it gives the line 
its height)
   {
-    tmpCharStyle = defaultCharStyle;
+    tmpCharStyle = std::move(defaultCharStyle);
     auto iter = styleOverrides.find(0);
     if (iter != styleOverrides.end())
       tmpCharStyle.overrideStyle(iter->second);
diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index 30d06c4..af203f9 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -1803,7 +1803,7 @@ void 
libcdr::CMXParser::readRdot(librevenge::RVNGInputStream *input)
     }
     else
       return;
-    m_parserState.m_dashArrays[j] = dots;
+    m_parserState.m_dashArrays[j] = std::move(dots);
   }
 }
 
diff --git a/src/lib/libcdr_utils.cpp b/src/lib/libcdr_utils.cpp
index 97442cb..14c4e49 100644
--- a/src/lib/libcdr_utils.cpp
+++ b/src/lib/libcdr_utils.cpp
@@ -509,7 +509,7 @@ void libcdr::writeU32(librevenge::RVNGBinaryData &buffer, 
const int value)
   buffer.append((unsigned char)((value >> 24) & 0xFF));
 }
 
-void libcdr::appendCharacters(librevenge::RVNGString &text, 
std::vector<unsigned char> characters, unsigned short charset)
+void libcdr::appendCharacters(librevenge::RVNGString &text, const 
std::vector<unsigned char> &characters, unsigned short charset)
 {
   if (characters.empty())
     return;
@@ -690,7 +690,7 @@ void libcdr::appendCharacters(librevenge::RVNGString &text, 
std::vector<unsigned
 #endif
 }
 
-void libcdr::appendCharacters(librevenge::RVNGString &text, 
std::vector<unsigned char> characters)
+void libcdr::appendCharacters(librevenge::RVNGString &text, const 
std::vector<unsigned char> &characters)
 {
   if (characters.empty())
     return;
diff --git a/src/lib/libcdr_utils.h b/src/lib/libcdr_utils.h
index 4df5d89..ebfe1c9 100644
--- a/src/lib/libcdr_utils.h
+++ b/src/lib/libcdr_utils.h
@@ -91,8 +91,8 @@ int cdr_round(double d);
 
 void writeU16(librevenge::RVNGBinaryData &buffer, const int value);
 void writeU32(librevenge::RVNGBinaryData &buffer, const int value);
-void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> 
characters, unsigned short charset);
-void appendCharacters(librevenge::RVNGString &text, std::vector<unsigned char> 
characters);
+void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned 
char> &characters, unsigned short charset);
+void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned 
char> &characters);
 void appendUTF8Characters(librevenge::RVNGString &text, std::vector<unsigned 
char> characters);
 
 #ifdef DEBUG
commit a1734cc9dca380c96991a148ce87aae2c178eb6b
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun Nov 15 21:28:20 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun Nov 15 21:28:20 2026 +0000

    cid#1708434 Dereference before null check
    
    and
    
    cid#1708435 Dereference before null check
    
    use the caller's stream directly so only the substream pointer, which
    can really be null, gets checked, and replace CDRDummyDeleter with
    makeUnownedStreamPtr as libvisio and libe-book do
    
    Change-Id: Ic8dd1bc6480325806d381876e0edcf725740acb2

diff --git a/src/lib/CDRDocument.cpp b/src/lib/CDRDocument.cpp
index 57f6f82..ae065bb 100644
--- a/src/lib/CDRDocument.cpp
+++ b/src/lib/CDRDocument.cpp
@@ -64,27 +64,19 @@ CDRAPI bool 
libcdr::CDRDocument::isSupported(librevenge::RVNGInputStream *input_
   if (!input_)
     return false;
 
-  librevenge::RVNGInputStream *tmpInput = input_;
-  std::shared_ptr<librevenge::RVNGInputStream> input(input_, 
CDRDummyDeleter());
-
-  input->seek(0, librevenge::RVNG_SEEK_SET);
-  unsigned version = getCDRVersion(input.get());
-  if (version)
+  input_->seek(0, librevenge::RVNG_SEEK_SET);
+  if (getCDRVersion(input_))
     return true;
-  if (tmpInput->isStructured())
-  {
-    input.reset(tmpInput->getSubStreamByName("content/riffData.cdr"));
-    if (!input)
-      input.reset(tmpInput->getSubStreamByName("content/root.dat"));
-  }
-  tmpInput->seek(0, librevenge::RVNG_SEEK_SET);
+  if (!input_->isStructured())
+    return false;
+  std::unique_ptr<librevenge::RVNGInputStream> 
input(input_->getSubStreamByName("content/riffData.cdr"));
+  if (!input)
+    input.reset(input_->getSubStreamByName("content/root.dat"));
+  input_->seek(0, librevenge::RVNG_SEEK_SET);
   if (!input)
     return false;
   input->seek(0, librevenge::RVNG_SEEK_SET);
-  version = getCDRVersion(input.get());
-  if (!version)
-    return false;
-  return true;
+  return getCDRVersion(input.get()) != 0;
 }
 catch (...)
 {
@@ -104,36 +96,34 @@ CDRAPI bool 
libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input_, libr
   if (!input_ || !painter)
     return false;
 
-  std::shared_ptr<librevenge::RVNGInputStream> input(input_, 
CDRDummyDeleter());
-
-  input->seek(0, librevenge::RVNG_SEEK_SET);
+  input_->seek(0, librevenge::RVNG_SEEK_SET);
   bool retVal = false;
   unsigned version = 0;
   try
   {
-    version = getCDRVersion(input.get());
+    version = getCDRVersion(input_);
     if (version)
     {
-      input->seek(0, librevenge::RVNG_SEEK_SET);
+      input_->seek(0, librevenge::RVNG_SEEK_SET);
       CDRParserState ps;
       std::vector<std::unique_ptr<librevenge::RVNGInputStream>> 
dummyDataStreams;
       CDRStylesCollector stylesCollector(ps);
       CDRParser stylesParser(dummyDataStreams, &stylesCollector);
       if (version >= 300)
-        retVal = stylesParser.parseRecords(input.get());
+        retVal = stylesParser.parseRecords(input_);
       else
-        retVal = stylesParser.parseWaldo(input.get());
+        retVal = stylesParser.parseWaldo(input_);
       if (ps.m_pages.empty())
         retVal = false;
       if (retVal)
       {
-        input->seek(0, librevenge::RVNG_SEEK_SET);
+        input_->seek(0, librevenge::RVNG_SEEK_SET);
         CDRContentCollector contentCollector(ps, painter);
         CDRParser contentParser(dummyDataStreams, &contentCollector);
         if (version >= 300)
-          retVal = contentParser.parseRecords(input.get());
+          retVal = contentParser.parseRecords(input_);
         else
-          retVal = contentParser.parseWaldo(input.get());
+          retVal = contentParser.parseWaldo(input_);
       }
       return retVal;
     }
@@ -145,6 +135,7 @@ CDRAPI bool 
libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input_, libr
   }
 
   librevenge::RVNGInputStream *tmpInput = input_;
+  std::shared_ptr<librevenge::RVNGInputStream> input;
   try
   {
     std::vector<std::string> dataFiles;
@@ -191,7 +182,7 @@ CDRAPI bool 
libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input_, libr
       dataStreams.push_back(std::move(strm));
     }
     if (!input)
-      input.reset(tmpInput, CDRDummyDeleter());
+      input = makeUnownedStreamPtr(tmpInput);
     CDRParserState ps;
     {
       // libcdr extension to the getSubStreamByName. Will extract the first 
stream in the
diff --git a/src/lib/libcdr_utils.h b/src/lib/libcdr_utils.h
index 5f3fccb..4df5d89 100644
--- a/src/lib/libcdr_utils.h
+++ b/src/lib/libcdr_utils.h
@@ -61,10 +61,11 @@ void debugPrint(const char *format, ...) 
CDR_ATTRIBUTE_PRINTF(1, 2);
 namespace libcdr
 {
 
-struct CDRDummyDeleter
+// The result points at input but owns nothing, so the caller keeps input 
alive.
+inline std::shared_ptr<librevenge::RVNGInputStream> 
makeUnownedStreamPtr(librevenge::RVNGInputStream *const input)
 {
-  void operator()(void *) const {}
-};
+  return 
std::shared_ptr<librevenge::RVNGInputStream>(std::shared_ptr<librevenge::RVNGInputStream>(),
 input);
+}
 
 template<typename T, typename... Args>
 std::unique_ptr<T> make_unique(Args &&... args)
commit 6be09cc0287d4873710dab5b5a0b11f8ab5e59a1
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun Nov 15 21:27:46 2026 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun Nov 15 21:27:46 2026 +0000

    cid#1219658 Untrusted loop bound
    
    and
    
    cid#1219655 Untrusted loop bound
    cid#1219657 Untrusted loop bound
    cid#1219656 Untrusted loop bound
    
    limit the text record counts in the Txsm readers to what the rest of
    the stream can hold, at the smallest record size, as the other counts
    in CDRParser already are
    
    Change-Id: Ia362c6d0a58d6a5aa4e35ca2ea80d08f23b8958a

diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 995d814..cde7bde 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -2817,6 +2817,8 @@ void 
libcdr::CDRParser::readTxsm(librevenge::RVNGInputStream *input, unsigned le
         input->seek(1, librevenge::RVNG_SEEK_CUR);
 
       unsigned numStyles = readU32(input);
+      if (numStyles > getRemainingLength(input) / 3)
+        numStyles = getRemainingLength(input) / 3;
       std::map<unsigned, CDRStyle> styles;
       for (unsigned i = 0; i < numStyles; ++i)
       {
@@ -2953,6 +2955,8 @@ void 
libcdr::CDRParser::readTxsm16(librevenge::RVNGInputStream *input)
     input->seek(37, librevenge::RVNG_SEEK_CUR);
 
     unsigned numFrames = readU32(input);
+    if (numFrames > getRemainingLength(input) / 64)
+      numFrames = getRemainingLength(input) / 64;
 
     unsigned textId = 0;
     bool fitted = false;   // a text fitted to a path: its characters' places 
follow its text
@@ -3100,6 +3104,8 @@ void 
libcdr::CDRParser::readTxsm6(librevenge::RVNGInputStream *input)
       input->seek(8, librevenge::RVNG_SEEK_CUR); // Maybe flags
   }
   unsigned numPara = readU32(input);
+  if (numPara > getRemainingLength(input) / 16)
+    numPara = getRemainingLength(input) / 16;
   for (unsigned j=0; j<numPara; ++j)
   {
     unsigned stlId = readU32(input);
@@ -3187,8 +3193,10 @@ void 
libcdr::CDRParser::readTxsm5(librevenge::RVNGInputStream *input)
   {
     unsigned stlId = readU16(input);
     unsigned numSt = readU16(input);
+    if (numSt > getRemainingLength(input) / 36)
+      numSt = getRemainingLength(input) / 36;
     std::map<unsigned, CDRStyle> styles;
-    for (unsigned i= 0; i<numSt /* && getRemainingLength(input) >= 34 */; ++i)
+    for (unsigned i= 0; i<numSt; ++i)
     {
       CDRStyle style;
       unsigned char flag = readU8(input);

Reply via email to