Commit 3aa6d96a by Edward Thomson

tree: cast filename length in git_tree__parse_raw

Quiet down a warning from MSVC about how we're potentially losing data.
Ensure that we're within a uint16_t before we do.
parent 759502ed
...@@ -403,7 +403,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) ...@@ -403,7 +403,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL) if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL)
return tree_error("failed to parse tree: object is corrupted", NULL); return tree_error("failed to parse tree: object is corrupted", NULL);
if ((filename_len = nul - buffer) == 0) if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX)
return tree_error("failed to parse tree: can't parse filename", NULL); return tree_error("failed to parse tree: can't parse filename", NULL);
if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ) if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ)
...@@ -415,7 +415,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) ...@@ -415,7 +415,7 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size)
GIT_ERROR_CHECK_ALLOC(entry); GIT_ERROR_CHECK_ALLOC(entry);
entry->attr = attr; entry->attr = attr;
entry->filename_len = filename_len; entry->filename_len = (uint16_t)filename_len;
entry->filename = buffer; entry->filename = buffer;
entry->oid = (git_oid *) ((char *) buffer + filename_len + 1); entry->oid = (git_oid *) ((char *) buffer + filename_len + 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment