84d907
From 3da78400eafcccb97e2f2fd4b227ea40d794ede8 Mon Sep 17 00:00:00 2001
84d907
From: Sergey Poznyakoff <gray@gnu.org>
84d907
Date: Sat, 11 Feb 2023 11:57:39 +0200
84d907
Subject: [PATCH] Fix boundary checking in base-256 decoder
84d907
84d907
* src/list.c (from_header): Base-256 encoding is at least 2 bytes
84d907
long.
84d907
---
84d907
 src/list.c | 5 +++--
84d907
 1 file changed, 3 insertions(+), 2 deletions(-)
84d907
84d907
diff --git a/src/list.c b/src/list.c
84d907
index 9fafc425..86bcfdd1 100644
84d907
--- a/src/list.c
84d907
+++ b/src/list.c
84d907
@@ -881,8 +881,9 @@ from_header (char const *where0, size_t digs, char const *type,
84d907
 	  where++;
84d907
 	}
84d907
     }
84d907
-  else if (*where == '\200' /* positive base-256 */
84d907
-	   || *where == '\377' /* negative base-256 */)
84d907
+  else if (where <= lim - 2
84d907
+	   && (*where == '\200' /* positive base-256 */
84d907
+	       || *where == '\377' /* negative base-256 */))
84d907
     {
84d907
       /* Parse base-256 output.  A nonnegative number N is
84d907
 	 represented as (256**DIGS)/2 + N; a negative number -N is
84d907
-- 
84d907
2.38.1
84d907