[Rpm-maint] [rpm-software-management/rpm] Use int64_t for lengths (#1492)

Panu Matilainen notifications at github.com
Fri Feb 19 06:51:26 UTC 2021


@pmatilai commented on this pull request.



> @@ -467,15 +468,14 @@ static int dataLength(rpm_tagtype_t type, rpm_constdata_t p, rpm_count_t count,
 	break;
 
     default:
-	if (typeSizes[type] == -1)
-	    return -1;
-	length = typeSizes[(type & 0xf)] * count;
-	if (length < 0 || (se && (s + length) > se))
+	/* this won’t overflow, since ‘long_count’ is 64-bit */
+	length = typeSizes[type] * long_count;
+	if (length <= 0 || (se && length > se - s))

I don't see a need for an extra variable. You could just assign to length and multiply, or make eg typeSizes int64 type (and/or count itself for that matter)

Note that this ends up removing an old safety feature in the code, ie that `(type & 0xf)` ensures that we'll never access typeSizes out of bounds. Only there was that redundant `== -1` check before it, making it moot :facepalm: 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1492#pullrequestreview-593903977
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20210218/d2d02d4d/attachment-0001.html>


More information about the Rpm-maint mailing list