summaryrefslogtreecommitdiff
path: root/src/revwalk.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-07-04 16:06:07 +0200
committernulltoken <emeric.fermas@gmail.com>2012-07-11 20:40:12 +0200
commit118cf57d426ede29b6695204e707810bbe3888ef (patch)
treee7eaf8636f19523960b2e1d9ec4643eca736b1a0 /src/revwalk.c
parent5b071115294e2c7d4b36ac21842ef09c7edd02b6 (diff)
downloadlibgit2-118cf57d426ede29b6695204e707810bbe3888ef.tar.gz
revwalk: relax the parsing of the commit time
Diffstat (limited to 'src/revwalk.c')
-rw-r--r--src/revwalk.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/revwalk.c b/src/revwalk.c
index 7bcdc4af8..9dff283f5 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -188,7 +188,7 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
const size_t parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1;
unsigned char *buffer = raw->data;
unsigned char *buffer_end = buffer + raw->len;
- unsigned char *parents_start;
+ unsigned char *parents_start, *committer_start;
int i, parents = 0;
int commit_time;
@@ -219,17 +219,34 @@ static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawo
commit->out_degree = (unsigned short)parents;
+ if ((committer_start = buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
+ return commit_error(commit, "object is corrupted");
+
+ buffer++;
+
if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL)
return commit_error(commit, "object is corrupted");
- if ((buffer = memchr(buffer, '<', buffer_end - buffer)) == NULL ||
- (buffer = memchr(buffer, '>', buffer_end - buffer)) == NULL)
- return commit_error(commit, "malformed author information");
+ /* Skip trailing spaces */
+ while (buffer > committer_start && git__isspace(*buffer))
+ buffer--;
+
+ /* Seek for the begining of the pack of digits */
+ while (buffer > committer_start && git__isdigit(*buffer))
+ buffer--;
- while (*buffer == '>' || git__isspace(*buffer))
- buffer++;
+ /* Skip potential timezone offset */
+ if ((buffer > committer_start) && (*buffer == '+' || *buffer == '-')) {
+ buffer--;
+
+ while (buffer > committer_start && git__isspace(*buffer))
+ buffer--;
+
+ while (buffer > committer_start && git__isdigit(*buffer))
+ buffer--;
+ }
- if (git__strtol32(&commit_time, (char *)buffer, NULL, 10) < 0)
+ if ((buffer == committer_start) || (git__strtol32(&commit_time, (char *)(buffer + 1), NULL, 10) < 0))
return commit_error(commit, "cannot parse commit time");
commit->time = (time_t)commit_time;