[vlc-commits] [Git][videolan/vlc][3.0.x] contrib: ebml: use backported versions of string reading

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jul 30 09:38:09 UTC 2025



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
4f03ee47 by Steve Lhomme at 2025-07-30T08:27:03+00:00
contrib: ebml: use backported versions of string reading

The code is cleaner and doesn't leak local buffers when readFully() emits
an exception. As in "oss-fuzz 5479158623043584".

Backport sent upstream at https://github.com/Matroska-Org/libebml/pull/323

(cherry picked from commit bee5a09d3e231e125b8bc72d04fc6b62e81533a7)

- - - - -


3 changed files:

- + contrib/src/ebml/0001-EbmlString-ReadFully-use-automatic-memory-management.patch
- + contrib/src/ebml/0002-EbmlUnicodeString-use-std-string-when-reading-instea.patch
- contrib/src/ebml/rules.mak


Changes:

=====================================
contrib/src/ebml/0001-EbmlString-ReadFully-use-automatic-memory-management.patch
=====================================
@@ -0,0 +1,54 @@
+From bd77aaa19f0c658254f4e2a0c069a1bfcf0dbea2 Mon Sep 17 00:00:00 2001
+From: Moritz Bunkus <mo at bunkus.online>
+Date: Sat, 23 Dec 2023 09:33:04 +0100
+Subject: [PATCH 1/2] EbmlString::ReadFully: use automatic memory
+ management/fewer allocations
+
+(cherry picked from commit ae9bb2580c3e0a79496e72f79185256670abeb95)
+---
+ src/EbmlString.cpp | 26 +++++++++++---------------
+ 1 file changed, 11 insertions(+), 15 deletions(-)
+
+diff --git a/src/EbmlString.cpp b/src/EbmlString.cpp
+index e1f4597..66b3338 100644
+--- a/src/EbmlString.cpp
++++ b/src/EbmlString.cpp
+@@ -142,24 +142,20 @@ filepos_t EbmlString::ReadData(IOCallback & input, ScopeMode ReadFully)
+     return GetSize();
+ 
+   if (GetSize() == 0) {
+-    Value = "";
+-    SetValueIsSet();
++    Value.clear();
++
+   } else {
+-    auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::max()) ? new (std::nothrow) char[GetSize() + 1] : nullptr;
+-    if (Buffer == nullptr) {
+-      // unable to store the data, skip it
+-      input.setFilePointer(GetSize(), seek_current);
+-    } else {
+-      input.readFully(Buffer, GetSize());
+-      if (Buffer[GetSize()-1] != '\0') {
+-        Buffer[GetSize()] = '\0';
+-      }
+-      Value = Buffer;
+-      delete [] Buffer;
+-      SetValueIsSet();
+-    }
++    Value.resize(GetSize());
++    std::memset(&Value[0], 0, GetSize());
++    input.readFully(&Value[0], GetSize());
++
++    auto PosNull = Value.find('\0');
++    if (PosNull != std::string::npos)
++      Value.resize(PosNull);
+   }
+ 
++  SetValueIsSet();
++
+   return GetSize();
+ }
+ 
+-- 
+2.45.1.windows.1
+


=====================================
contrib/src/ebml/0002-EbmlUnicodeString-use-std-string-when-reading-instea.patch
=====================================
@@ -0,0 +1,50 @@
+From 12c0cebbbda310420a935c021014bffc2b179102 Mon Sep 17 00:00:00 2001
+From: Moritz Bunkus <mo at bunkus.online>
+Date: Fri, 22 Dec 2023 17:50:15 +0100
+Subject: [PATCH 2/2] EbmlUnicodeString: use std::string when reading instead
+ of manual memory management
+
+(cherry picked from commit 6b83a0f6f6d1ae7fa14a4f96e70914c1a9686ed4)
+---
+ src/EbmlUnicodeString.cpp | 22 +++++++---------------
+ 1 file changed, 7 insertions(+), 15 deletions(-)
+
+diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp
+index 56f74ce..570af17 100644
+--- a/src/EbmlUnicodeString.cpp
++++ b/src/EbmlUnicodeString.cpp
+@@ -308,24 +308,16 @@ filepos_t EbmlUnicodeString::ReadData(IOCallback & input, ScopeMode ReadFully)
+ 
+   if (GetSize() == 0) {
+     Value = static_cast<UTFstring::value_type>(0);
+-    SetValueIsSet();
++
+   } else {
+-    auto Buffer = (GetSize() + 1 < std::numeric_limits<std::size_t>::max()) ? new (std::nothrow) char[GetSize()+1] : nullptr;
+-    if (Buffer == nullptr) {
+-      // impossible to read, skip it
+-      input.setFilePointer(GetSize(), seek_current);
+-    } else {
+-      input.readFully(Buffer, GetSize());
+-      if (Buffer[GetSize()-1] != 0) {
+-        Buffer[GetSize()] = 0;
+-      }
+-
+-      Value.SetUTF8(Buffer); // implicit conversion to std::string
+-      delete [] Buffer;
+-      SetValueIsSet();
+-    }
++    std::string Buffer(static_cast<std::string::size_type>(GetSize()), static_cast<char>(0));
++    input.readFully(&Buffer[0], GetSize());
++
++    Value.SetUTF8(Buffer.c_str()); // Let conversion to std::string cut off at the first 0
+   }
+ 
++  SetValueIsSet();
++
+   return GetSize();
+ }
+ 
+-- 
+2.45.1.windows.1
+


=====================================
contrib/src/ebml/rules.mak
=====================================
@@ -14,6 +14,8 @@ $(TARBALLS)/libebml-$(EBML_VERSION).tar.xz:
 
 ebml: libebml-$(EBML_VERSION).tar.xz .sum-ebml
 	$(UNPACK)
+	$(APPLY) $(SRC)/ebml/0001-EbmlString-ReadFully-use-automatic-memory-management.patch
+	$(APPLY) $(SRC)/ebml/0002-EbmlUnicodeString-use-std-string-when-reading-instea.patch
 	$(MOVE)
 
 .ebml: ebml toolchain.cmake



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4f03ee47ef2f37acc4af4649d0ac9f99a572020c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/4f03ee47ef2f37acc4af4649d0ac9f99a572020c
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list