@matheusbsbs / matheus-bagliano / commits / aac65ed1bc
Fork 0

Fix possible coredump with fast-import --import-marks

When e8438420bb7d368bec3647b90c557b9931582267 allowed us to reload the marks table on subsequent runs of fast-import we really broke things, as we set pack_id to MAX_PACK_ID for any objects we imported into the marks table. Creating a branch from that mark should fail as we attempt to read the object through a non-existant packed_git pointer. Instead we have to use the normal Git object system to locate the older commit, as we ourselves do not have a reference to the packed_git it resides in. This bug only occurred because t9300 was not complete enough. When we added the --import-marks feature we didn't actually test its implementation enough to verify the function worked as intended. I have corrected that, and included the changes as part of this fix. Prior versions of fast-import fail the new test(s); this commit allows them to pass. Credit for this bug find goes to Simon Hausmann <simon@lst.de> as he recently identified a similiar bug in the tree lazy-loading path. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 24, 2007 at 00:32 UTC aac65ed1bc63619d32516079995f5cbe4bb46492
2 files changed +36 -5
fast-import.c
+7 -5
@@ -1709,14 +1709,16 @@ static void cmd_from(struct branch *b)
1709 } else if (*from == ':') {
1710 uintmax_t idnum = strtoumax(from + 1, NULL, 10);
1711 struct object_entry *oe = find_mark(idnum);
1712 - unsigned long size;
1713 - char *buf;
1712 if (oe->type != OBJ_COMMIT)
1713 die("Mark :%" PRIuMAX " not a commit", idnum);
1714 hashcpy(b->sha1, oe->sha1);
1717 - buf = gfi_unpack_entry(oe, &size);
1718 - cmd_from_commit(b, buf, size);
1719 - free(buf);
1715 + if (oe->pack_id != MAX_PACK_ID) {
1716 + unsigned long size;
1717 + char *buf = gfi_unpack_entry(oe, &size);
1718 + cmd_from_commit(b, buf, size);
1719 + free(buf);
1720 + } else
1721 + cmd_from_existing(b);
1722 } else if (!get_sha1(from, b->sha1))
1723 cmd_from_existing(b);
1724 else
t/t9300-fast-import.sh
+29
@@ -119,6 +119,35 @@ test_expect_success \
119 </dev/null &&
120 git diff -u expect marks.new'
121
122 +test_tick
123 +cat >input <<INPUT_END
124 +commit refs/heads/verify--import-marks
125 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
126 +data <<COMMIT
127 +recreate from :5
128 +COMMIT
129 +
130 +from :5
131 +M 755 :2 copy-of-file2
132 +
133 +INPUT_END
134 +test_expect_success \
135 + 'A: verify marks import does not crash' \
136 + 'git-fast-import --import-marks=marks.out <input &&
137 + git-whatchanged verify--import-marks'
138 +test_expect_success \
139 + 'A: verify pack' \
140 + 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
141 +cat >expect <<EOF
142 +:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
143 +EOF
144 +git-diff-tree -M -r master verify--import-marks >actual
145 +test_expect_success \
146 + 'A: verify diff' \
147 + 'compare_diff_raw expect actual &&
148 + test `git-rev-parse --verify master:file2` \
149 + = `git-rev-parse --verify verify--import-marks:copy-of-file2`'
150 +
151 ###
152 ### series B
153 ###