Commit Diff


commit - 9d3ac73fac074519ca1ef3696df8f0240dcd0ca7
commit + 26ec500845da3b596b42ceac82f7da2875e68f80
blob - 909e0630a41461a27ffa9e8dd02d673281d4e527
blob + 0bd35c9b4c54277b44c5b1c1a52a501f03d87f0a
--- lib/pack.c
+++ lib/pack.c
@@ -937,7 +937,7 @@ parse_negative_offset(int64_t *offset, size_t *len, st
 		if (pack->map) {
 			size_t mapoff;
 
-			if (delta_offset + *len > SIZE_MAX) {
+			if (delta_offset > SIZE_MAX - *len) {
 				return got_error_fmt(GOT_ERR_PACK_OFFSET,
 				    "mapoff %lld would overflow size_t",
 				    (long long)delta_offset + *len);
@@ -1095,7 +1095,7 @@ got_pack_parse_ref_delta(struct got_object_id *id,
 	if (pack->map) {
 		size_t mapoff;
 
-		if (delta_offset + tslen > SIZE_MAX) {
+		if (delta_offset > SIZE_MAX - tslen) {
 			return got_error_fmt(GOT_ERR_PACK_OFFSET,
 			    "mapoff %lld would overflow size_t",
 			    (long long)delta_offset + tslen);