convert_commit_object() only enters the "tree ", "parent " and "mergetag " cases when something follows the space. A line like "parent \n" falls through to the final "else", which rejects any line it does not know. The next commit makes that "else" copy unknown lines unchanged. Then "parent \n" would be copied into the compat object instead of being rejected. Worse, a "mergetag " line whose tag starts on the next line would be copied together with the unconverted object ID in that tag. Use "<=" instead of "<", so that these lines enter their own case and are rejected there. An empty "tree " or "parent " fails the length check before parse_oid_hex_algop() is reached. An empty "mergetag " leaves a tag that doesn't start with "object ", which convert_tag_object() rejects. This doesn't change behaviour: these lines are rejected as before, only now with an error saying why, e.g. "bad parent in commit". Signed-off-by: Adrian Ratiu <adri…@collabora.com> --- object-file-convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/object-file-convert.c b/object-file-convert.c index 63ee18630b..af14cf8300 100644 --- a/object-file-convert.c +++ b/object-file-convert.c @@ -167,7 +167,7 @@ static int convert_commit_object(struct repository *repo, if (!eol) return error(_("bad %s in commit"), "line"); - if (((bufptr + 5) < eol) && !memcmp(bufptr, "tree ", 5)) + if (((bufptr + 5) <= eol) && !memcmp(bufptr, "tree ", 5)) { if (((bufptr + tree_entry_len) != eol) || parse_oid_hex_algop(bufptr + 5, &oid, &p, from) || @@ -179,7 +179,7 @@ static int convert_commit_object(struct repository *repo, "tree", oid_to_hex(&oid)); strbuf_addf(out, "tree %s\n", oid_to_hex(&mapped_oid)); } - else if (((bufptr + 7) < eol) && !memcmp(bufptr, "parent ", 7)) + else if (((bufptr + 7) <= eol) && !memcmp(bufptr, "parent ", 7)) { if (((bufptr + parent_entry_len) != eol) || parse_oid_hex_algop(bufptr + 7, &oid, &p, from) || @@ -192,7 +192,7 @@ static int convert_commit_object(struct repository *repo, strbuf_addf(out, "parent %s\n", oid_to_hex(&mapped_oid)); } - else if (((bufptr + 9) < eol) && !memcmp(bufptr, "mergetag ", 9)) + else if (((bufptr + 9) <= eol) && !memcmp(bufptr, "mergetag ", 9)) { struct strbuf tag = STRBUF_INIT, new_tag = STRBUF_INIT;
-- 2.56.1