OSDN Git Service

avformat/cache: Avoid int-overflow in cache compare function
authorBryan Huh <bryan@box.com>
Mon, 9 Nov 2015 00:35:01 +0000 (16:35 -0800)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 9 Nov 2015 18:25:05 +0000 (19:25 +0100)
cache protocol indexes its cache using AVTreeNodes which require a cmp
function for inserting and searching new cache-entries. This cmp
function expects a 32-bit int return value (negative, zero, or positive)
but the cache cmp function returns an int64_t which can overflow the
int, giving negative numbers for when it should be positive, vice versa.
This manifests itself only for very large files (e.g. 4GB+)

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/cache.c

index 31f63e6..d41161d 100644 (file)
@@ -67,7 +67,7 @@ typedef struct Context {
 
 static int cmp(const void *key, const void *node)
 {
-    return (*(const int64_t *) key) - ((const CacheEntry *) node)->logical_pos;
+    return FFDIFFSIGN(*(const int64_t *)key, ((const CacheEntry *) node)->logical_pos);
 }
 
 static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options)