]> git.proxmox.com Git - libgit2.git/commitdiff
improve test for index extension truncation
authorEdward Thomson <ethomson@microsoft.com>
Fri, 31 May 2013 16:41:33 +0000 (11:41 -0500)
committerEdward Thomson <ethomson@microsoft.com>
Fri, 31 May 2013 16:41:33 +0000 (11:41 -0500)
src/index.c

index d5d9aef48c7d4d07ef69c3a003f07632640e10da..45ce2f3d6378f7d84e5128180b736e4279c80dbe 100644 (file)
@@ -1575,7 +1575,8 @@ static size_t read_extension(git_index *index, const char *buffer, size_t buffer
 
        total_size = dest.extension_size + sizeof(struct index_extension);
 
-       if (buffer_size - total_size < INDEX_FOOTER_SIZE)
+       if (buffer_size < total_size ||
+               buffer_size - total_size < INDEX_FOOTER_SIZE)
                return 0;
 
        /* optional extension */
@@ -1661,7 +1662,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 
                /* see if we have read any bytes from the extension */
                if (extension_size == 0)
-                       return index_error_invalid("extension size is zero");
+                       return index_error_invalid("extension is truncated");
 
                seek_forward(extension_size);
        }