From 4a6cd10658be56430c4801ea6189fdbf2faf222d Mon Sep 17 00:00:00 2001
From: pompolic <pompolic@special-circumstanc.es>
Date: Thu, 25 Jun 2020 14:31:09 +0200
Subject: [PATCH] Fix overflow issue

---
 pdf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pdf.c b/pdf.c
index faef9d7..0700414 100644
--- a/pdf.c
+++ b/pdf.c
@@ -623,6 +623,8 @@ act_numb(const HParseResult *p, void *u)
 {
 	const HParsedToken *x = p->ast;
 	int64_t sgn = 1;
+	uint64_t toolarge = -(INT64_MIN+1); // XXX bypass not being able to negate INT64_MIN due to two's complement
+	toolarge += 1;
 
 	if (x->token_type == TT_SEQUENCE) {
 		sgn = H_FIELD_SINT(0);
@@ -632,7 +634,7 @@ act_numb(const HParseResult *p, void *u)
 	assert(sgn == 1 || sgn == -1);
 	switch (x->token_type) {
 	case TT_UINT:
-		if (x->uint > -INT64_MIN)	/* would overflow */
+		if (x->uint > toolarge)	/* would overflow */
 			return NULL;	// XXX structured error type
 		return H_MAKE_SINT(sgn * x->uint);
 	case TT_DOUBLE:
-- 
GitLab