]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
flac_afh: Check for possible integer overflows.
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 20 May 2025 18:56:36 +0000 (20:56 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 21 May 2025 16:16:07 +0000 (18:16 +0200)
This is a callback function which should carefully check its inputs.

flac_afh.c

index 1d0b3bf45dc60acd3f76288544803ee84f052338..ab71670568905135bc7a9a84f02098db169430c6 100644 (file)
@@ -433,10 +433,10 @@ static size_t temp_write_cb(const void *ptr, size_t size, size_t nmemb,
        FLAC__IOHandle handle)
 {
        int ret, fd = *(int *)handle;
-       size_t n = size * nmemb; /* FIXME: possible overflow */
+       size_t n;
 
+       assert(!__builtin_mul_overflow(nmemb, size, &n));
        ret = write_all(fd, ptr, n);
-
        /*
         * libflac expects POSIX semantics: If an error occurs, or the end of
         * the file is reached, the return value is a short item count or zero.