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