CVE-2021-31255 (published 2021-04-19T19:15Z)

Buffer overflow in the abst_box_read function in MP4Box in GPAC 1.0.1 allows attackers to cause a denial of service or execute arbitrary code via a crafted file.

Severity: MEDIUM
CVSS v2 base score: 6.8 (AV:N/AC:M/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 7.8, HIGH (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-120
cwe_name: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
description: The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
extended_description: A buffer overflow condition exists when a product attempts to put more data in a buffer than it can hold, or when it attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the product copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
         

Fix information:
repo_url: https://github.com/gpac/gpac
commit_details: repo_url: https://github.com/gpac/gpac
author: jeanlf
author_date: 2021-04-08 10:07:35+02:00
msg: fixed #1733
repository: repo_url: https://github.com/gpac/gpac
repo_name: gpac/gpac
description: GPAC Ultramedia OSS for Video Streaming & Next-Gen Multimedia Transcoding, Packaging & Delivery
repo_language: C
owner: gpac
file_changes: filename: box_code_adobe.c
change_type: ModificationType.MODIFY
diff: @@ -79,6 +79,7 @@ GF_Err abst_box_read(GF_Box *s, GF_BitStream *bs)
 	int i;
 	u32 tmp_strsize;
 	char *tmp_str;
+	Bool zfound=GF_FALSE;
 	GF_Err e;
 
 	ISOM_DECREASE_SIZE(ptr, 25)
@@ -102,10 +103,14 @@ GF_Err abst_box_read(GF_Box *s, GF_BitStream *bs)
 		ISOM_DECREASE_SIZE(ptr, 1)
 		tmp_str[i] = gf_bs_read_u8(bs);
 		tmp_strsize--;
-		if (!tmp_str[i])
+		if (!tmp_str[i]) {
+			zfound = GF_TRUE;
 			break;
+		}
 		i++;
 	}
+	if (!zfound)
+		return GF_ISOM_INVALID_FILE;
 	if (i) {
 		ptr->movie_identifier = gf_strdup(tmp_str);
 	}
@@ -114,15 +119,20 @@ GF_Err abst_box_read(GF_Box *s, GF_BitStream *bs)
 	ptr->server_entry_count = gf_bs_read_u8(bs);
 	for (i=0; i<ptr->server_entry_count; i++) {
 		int j=0;
+		zfound = GF_FALSE;
 		tmp_strsize=(u32)ptr->size;
 		while (tmp_strsize) {
 			ISOM_DECREASE_SIZE(ptr, 1)
 			tmp_str[j] = gf_bs_read_u8(bs);
 			tmp_strsize--;
-			if (!tmp_str[j])
+			if (!tmp_str[j]) {
+				zfound = GF_TRUE;
 				break;
+			}
 			j++;
 		}
+		if (!zfound)
+			return GF_ISOM_INVALID_FILE;
 		if (j) {
 			gf_list_insert(ptr->server_entry_table, gf_strdup(tmp_str), i);
 		}
@@ -132,16 +142,21 @@ GF_Err abst_box_read(GF_Box *s, GF_BitStream *bs)
 	ptr->quality_entry_count = gf_bs_read_u8(bs);
 	for (i=0; i<ptr->quality_entry_count; i++) {
 		int j=0;
+		zfound = GF_FALSE;
 		tmp_strsize=(u32)ptr->size;
 		while (tmp_strsize) {
 			ISOM_DECREASE_SIZE(ptr, 1)
 			tmp_str[j] = gf_bs_read_u8(bs);
 			tmp_strsize--;
-			if (!tmp_str[j])
+			if (!tmp_str[j]) {
+				zfound = GF_TRUE;
 				break;
+			}
 			j++;
 		}
 
+		if (!zfound)
+			return GF_ISOM_INVALID_FILE;
 		if (j) {
 			gf_list_insert(ptr->quality_entry_table, gf_strdup(tmp_str), i);
 		}
@@ -149,28 +164,38 @@ GF_Err abst_box_read(GF_Box *s, GF_BitStream *bs)
 
 	i=0;
 	tmp_strsize=(u32)ptr->size;
+	zfound = GF_FALSE;
 	while (tmp_strsize) {
 		ISOM_DECREASE_SIZE(ptr, 1)
 		tmp_str[i] = gf_bs_read_u8(bs);
 		tmp_strsize--;
-		if (!tmp_str[i])
+		if (!tmp_str[i]) {
+			zfound = GF_TRUE;
 			break;
+		}
 		i++;
 	}
+	if (!zfound)
+		return GF_ISOM_INVALID_FILE;
 	if (i) {
 		ptr->drm_data = gf_strdup(tmp_str);
 	}
 
 	i=0;
 	tmp_strsize=(u32)ptr->size;
+	zfound = GF_FALSE;
 	while (tmp_strsize) {
 		ISOM_DECREASE_SIZE(ptr, 1)
 		tmp_str[i] = gf_bs_read_u8(bs);
 		tmp_strsize--;
-		if (!tmp_str[i])
+		if (!tmp_str[i]) {
+			zfound = GF_TRUE;
 			break;
+		}
 		i++;
 	}
+	if (!zfound)
+		return GF_ISOM_INVALID_FILE;
 	if (i) {
 		ptr->meta_data = gf_strdup(tmp_str);
 	}

programming_language: C