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