summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiroslav Šulc <fordfrog@gentoo.org>2023-06-04 09:48:36 +0200
committerMiroslav Šulc <fordfrog@gentoo.org>2023-06-04 09:48:36 +0200
commita61d5d15bb1c95d443c0e00c94b5b023d090a889 (patch)
treedf4bde9c90bb3b621abe343e068946347b48b874 /media-libs/libmp4v2
parentsci-geosciences/opencpn: fix docs location (diff)
downloadgentoo-a61d5d15bb1c95d443c0e00c94b5b023d090a889.tar.gz
gentoo-a61d5d15bb1c95d443c0e00c94b5b023d090a889.tar.bz2
gentoo-a61d5d15bb1c95d443c0e00c94b5b023d090a889.zip
media-libs/libmp4v2: fixed mem leaks
Bug: https://bugs.gentoo.org/907275 Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
Diffstat (limited to 'media-libs/libmp4v2')
-rw-r--r--media-libs/libmp4v2/files/libmp4v2-2.0.0-unsigned-int-cast.patch21
-rw-r--r--media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-1.patch150
-rw-r--r--media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-2.patch30
-rw-r--r--media-libs/libmp4v2/libmp4v2-2.1.3-r1.ebuild34
4 files changed, 214 insertions, 21 deletions
diff --git a/media-libs/libmp4v2/files/libmp4v2-2.0.0-unsigned-int-cast.patch b/media-libs/libmp4v2/files/libmp4v2-2.0.0-unsigned-int-cast.patch
index 25830bc596be..a5b28c32022f 100644
--- a/media-libs/libmp4v2/files/libmp4v2-2.0.0-unsigned-int-cast.patch
+++ b/media-libs/libmp4v2/files/libmp4v2-2.0.0-unsigned-int-cast.patch
@@ -4,17 +4,6 @@ Date: Thu, 6 Aug 2020 15:22:04 +0200
Subject: [PATCH] Static cast to unsigned int for cases
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
----
- libutil/Utility.cpp | 2 +-
- util/mp4art.cpp | 2 +-
- util/mp4chaps.cpp | 2 +-
- util/mp4file.cpp | 2 +-
- util/mp4subtitle.cpp | 2 +-
- util/mp4track.cpp | 2 +-
- 6 files changed, 6 insertions(+), 6 deletions(-)
-
-diff --git a/libutil/Utility.cpp b/libutil/Utility.cpp
-index 76cdd12..d6739d4 100644
--- a/libutil/Utility.cpp
+++ b/libutil/Utility.cpp
@@ -493,7 +493,7 @@ Utility::process_impl()
@@ -26,8 +15,6 @@ index 76cdd12..d6739d4 100644
case 'z':
_optimize = true;
break;
-diff --git a/util/mp4art.cpp b/util/mp4art.cpp
-index add935e..6e7f531 100644
--- a/util/mp4art.cpp
+++ b/util/mp4art.cpp
@@ -376,7 +376,7 @@ ArtUtility::utility_option( int code, bool& handled )
@@ -39,8 +26,6 @@ index add935e..6e7f531 100644
case LC_ART_ANY:
_artFilter = numeric_limits<uint32_t>::max();
break;
-diff --git a/util/mp4chaps.cpp b/util/mp4chaps.cpp
-index 98400f8..ccc8b70 100644
--- a/util/mp4chaps.cpp
+++ b/util/mp4chaps.cpp
@@ -632,7 +632,7 @@ ChapterUtility::utility_option( int code, bool& handled )
@@ -52,8 +37,6 @@ index 98400f8..ccc8b70 100644
case 'A':
case LC_CHPT_ANY:
_ChapterType = MP4ChapterTypeAny;
-diff --git a/util/mp4file.cpp b/util/mp4file.cpp
-index c27844b..b127cd1 100644
--- a/util/mp4file.cpp
+++ b/util/mp4file.cpp
@@ -189,7 +189,7 @@ FileUtility::utility_option( int code, bool& handled )
@@ -65,8 +48,6 @@ index c27844b..b127cd1 100644
case LC_LIST:
_action = &FileUtility::actionList;
break;
-diff --git a/util/mp4subtitle.cpp b/util/mp4subtitle.cpp
-index 7462153..19d977d 100644
--- a/util/mp4subtitle.cpp
+++ b/util/mp4subtitle.cpp
@@ -164,7 +164,7 @@ SubtitleUtility::utility_option( int code, bool& handled )
@@ -78,8 +59,6 @@ index 7462153..19d977d 100644
case LC_LIST:
_action = &SubtitleUtility::actionList;
break;
-diff --git a/util/mp4track.cpp b/util/mp4track.cpp
-index d550506..cd63d7e 100644
--- a/util/mp4track.cpp
+++ b/util/mp4track.cpp
@@ -788,7 +788,7 @@ TrackUtility::utility_option( int code, bool& handled )
diff --git a/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-1.patch b/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-1.patch
new file mode 100644
index 000000000000..a12c24f4e3fe
--- /dev/null
+++ b/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-1.patch
@@ -0,0 +1,150 @@
+From c724815a541b763455ff38922af96f652627bce6 Mon Sep 17 00:00:00 2001
+From: Robert Kausch <robert.kausch@freac.org>
+Date: Tue, 16 May 2023 00:19:02 +0200
+Subject: [PATCH] Fix memory leaks in case MP4File::ReadBytes() throws an
+ exception.
+
+--- a/src/atom_rtp.cpp
++++ b/src/atom_rtp.cpp
+@@ -125,12 +125,19 @@ void MP4RtpAtom::ReadHntiType()
+
+ // read sdp string, length is implicit in size of atom
+ uint64_t size = GetEnd() - m_File.GetPosition();
+- char* data = (char*)MP4Malloc(size + 1);
++ char* data = (char*) MP4Malloc(size + 1);
+ ASSERT(data != NULL);
+- m_File.ReadBytes((uint8_t*)data, size);
+- data[size] = '\0';
+- ((MP4StringProperty*)m_pProperties[1])->SetValue(data);
+- MP4Free(data);
++ try {
++ m_File.ReadBytes((uint8_t*) data, size);
++ data[size] = '\0';
++ ((MP4StringProperty*) m_pProperties[1])->SetValue(data);
++ MP4Free(data);
++ }
++ catch (Exception*) {
++ // free memory and rethrow
++ MP4Free(data);
++ throw;
++ }
+ }
+
+ void MP4RtpAtom::Write()
+--- a/src/atom_sdp.cpp
++++ b/src/atom_sdp.cpp
+@@ -36,12 +36,19 @@ void MP4SdpAtom::Read()
+ {
+ // read sdp string, length is implicit in size of atom
+ uint64_t size = GetEnd() - m_File.GetPosition();
+- char* data = (char*)MP4Malloc(size + 1);
++ char* data = (char*) MP4Malloc(size + 1);
+ ASSERT(data != NULL);
+- m_File.ReadBytes((uint8_t*)data, size);
+- data[size] = '\0';
+- ((MP4StringProperty*)m_pProperties[0])->SetValue(data);
+- MP4Free(data);
++ try {
++ m_File.ReadBytes((uint8_t*) data, size);
++ data[size] = '\0';
++ ((MP4StringProperty*) m_pProperties[0])->SetValue(data);
++ MP4Free(data);
++ }
++ catch (Exception*) {
++ // free memory and rethrow
++ MP4Free(data);
++ throw;
++ }
+ }
+
+ void MP4SdpAtom::Write()
+--- a/src/mp4file_io.cpp
++++ b/src/mp4file_io.cpp
+@@ -325,19 +325,26 @@ char* MP4File::ReadString()
+ {
+ uint32_t length = 0;
+ uint32_t alloced = 64;
+- char* data = (char*)MP4Malloc(alloced);
+-
+- do {
+- if (length == alloced) {
+- data = (char*)MP4Realloc(data, alloced * 2);
+- if (data == NULL) return NULL;
+- alloced *= 2;
+- }
+- ReadBytes((uint8_t*)&data[length], 1);
+- length++;
+- } while (data[length - 1] != 0);
+-
+- data = (char*)MP4Realloc(data, length);
++ char* data = (char*) MP4Malloc(alloced);
++ try {
++ do {
++ if (length == alloced) {
++ data = (char*) MP4Realloc(data, alloced * 2);
++ if (data == NULL)
++ return NULL;
++ alloced *= 2;
++ }
++ ReadBytes((uint8_t*) &data[length], 1);
++ length++;
++ } while (data[length - 1] != 0);
++
++ data = (char*) MP4Realloc(data, length);
++ }
++ catch (Exception*) {
++ // free memory and rethrow
++ MP4Free(data);
++ throw;
++ }
+ return data;
+ }
+
+@@ -384,21 +391,34 @@ char* MP4File::ReadCountedString(uint8_t charSize, bool allowExpandedCount, uint
+ }
+
+ uint32_t byteLength = charLength * charSize;
+- char* data = (char*)MP4Malloc(byteLength + 1);
+- if (byteLength > 0) {
+- ReadBytes((uint8_t*)data, byteLength);
+- }
+- data[byteLength] = '\0';
+-
+- // read padding
+- if (fixedLength) {
+- const uint8_t padsize = fixedLength - byteLength -1U;
+- if( padsize ) {
+- uint8_t* padbuf = (uint8_t*)malloc( padsize );
+- ReadBytes( padbuf, padsize );
+- free( padbuf );
++ char* data = (char*) MP4Malloc(byteLength + 1);
++ try {
++ if (byteLength > 0)
++ ReadBytes((uint8_t*) data, byteLength);
++ data[byteLength] = '\0';
++
++ // read padding
++ if (fixedLength) {
++ const uint8_t padsize = fixedLength - byteLength -1U;
++ if (padsize) {
++ uint8_t* padbuf = (uint8_t*) MP4Malloc(padsize);
++ try {
++ ReadBytes(padbuf, padsize);
++ MP4Free(padbuf);
++ }
++ catch (Exception*) {
++ // free memory and rethrow
++ MP4Free(padbuf);
++ throw;
++ }
++ }
+ }
+ }
++ catch (Exception*) {
++ // free memory and rethrow
++ MP4Free(data);
++ throw;
++ }
+
+ return data;
+ }
diff --git a/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-2.patch b/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-2.patch
new file mode 100644
index 000000000000..800812a034d3
--- /dev/null
+++ b/media-libs/libmp4v2/files/libmp4v2-2.1.3-mem-leaks-2.patch
@@ -0,0 +1,30 @@
+From 0f97a87685c8fcf9d7b9b21167265b21b1c34cc5 Mon Sep 17 00:00:00 2001
+From: Robert Kausch <robert.kausch@freac.org>
+Date: Tue, 16 May 2023 00:11:53 +0200
+Subject: [PATCH] Fix memory leaks in MP4StringProperty and MP4BytesProperty
+ classes.
+
+--- a/src/mp4property.cpp
++++ b/src/mp4property.cpp
+@@ -343,6 +343,10 @@ void MP4StringProperty::SetCount(uint32_t count)
+ {
+ uint32_t oldCount = m_values.Size();
+
++ for (uint32_t i = count; i < oldCount; i++) {
++ MP4Free(m_values[i]);
++ }
++
+ m_values.Resize(count);
+
+ for (uint32_t i = oldCount; i < count; i++) {
+@@ -510,6 +514,10 @@ void MP4BytesProperty::SetCount(uint32_t count)
+ {
+ uint32_t oldCount = m_values.Size();
+
++ for (uint32_t i = count; i < oldCount; i++) {
++ MP4Free(m_values[i]);
++ }
++
+ m_values.Resize(count);
+ m_valueSizes.Resize(count);
+
diff --git a/media-libs/libmp4v2/libmp4v2-2.1.3-r1.ebuild b/media-libs/libmp4v2/libmp4v2-2.1.3-r1.ebuild
new file mode 100644
index 000000000000..99115cb4f656
--- /dev/null
+++ b/media-libs/libmp4v2/libmp4v2-2.1.3-r1.ebuild
@@ -0,0 +1,34 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+MY_P=${P/lib}
+
+inherit cmake
+
+DESCRIPTION="Functions for accessing ISO-IEC:14496-1:2001 MPEG-4 standard"
+HOMEPAGE="https://mp4v2.org/"
+SRC_URI="https://github.com/enzo1982/mp4v2/releases/download/v${PV}/${MY_P}.tar.bz2"
+
+LICENSE="MPL-1.1"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos"
+IUSE="utils"
+# Tests need DejaGnu but are non-existent (just an empty framework)
+RESTRICT="test"
+
+S="${WORKDIR}/${MY_P}"
+
+PATCHES=(
+ "${FILESDIR}/${PN}-2.0.0-unsigned-int-cast.patch"
+ "${FILESDIR}/${P}-mem-leaks-1.patch"
+ "${FILESDIR}/${P}-mem-leaks-2.patch"
+)
+
+src_configure() {
+ local mycmakeargs=(
+ -DBUILD_UTILS=$(usex utils)
+ )
+ cmake_src_configure
+}