-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Object parsing hardening #3956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object parsing hardening #3956
Conversation
When parsing tree entries from raw object data, we do not verify that the tree entry actually has a filename as well as a valid object ID. Fix this by asserting that the filename length is non-zero as well as asserting that there are at least `GIT_OID_RAWSZ` bytes left when parsing the OID.
By the way: is there some test logic for directly parsing raw objects? I didn't spot any while skimming the tests, but obviously it would be nice to have these fixes backed by some tests. |
@@ -462,6 +462,9 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) | |||
if (buffer <= buffer_end) { | |||
commit->raw_message = git__strndup(buffer, buffer_end - buffer); | |||
GITERR_CHECK_ALLOC(commit->raw_message); | |||
} else { | |||
commit->raw_message = git__strdup(""); | |||
GITERR_CHECK_ALLOC(commit->raw_message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny nitpick: This line could be moved beneath the if
/else
blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed, realized the same after posting this PR. Will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks for your careful eyes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
When parsing a commit, we will treat all bytes left after parsing the headers as the commit message. When no bytes are left, we leave the commit's message uninitialized. While uncommon to have a commit without message, this is the right behavior as Git unfortunately allows for empty commit messages. Given that this scenario is so uncommon, most programs acting on the commit message will never check if the message is actually set, which may lead to errors. To work around the error and not lay the burden of checking for empty commit messages to the developer, initialize the commit message with an empty string when no commit message is given.
594a409
to
a719ef5
Compare
Thanks! |
See the commit messages for more info. These commits fix #3936 and #3937. I bet there are more issues around here which I'd like to find. I think I'll try some more fuzzing with AFL around the object-parsing logic sometimes soon.