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

vcs-svn: Error out for v3 dumps

By ignoring the Text-Delta and Prop-Delta node fields, current svn-fe happily mistakes deltas for full text and instead of cleanly erroring out, it produces a valid but semantically bogus fast-import stream when fed a dump file in the modern "svnadmin dump --deltas" format. Dump file parsers are supposed to ignore header fields they don't understand (to allow for backward-compatible extensions), but they are also supposed to check the SVN-fs-dump-format-version header to prevent misinterpretation of non backward-compatible extensions. Do so. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 17, 2010 at 23:02 UTC b3e5bce1aa88721dd4565089960997836ce66add
2 files changed +47 -25
t/t9010-svn-fe.sh
+37 -22
@@ -4,29 +4,44 @@ test_description='check svn dumpfile importer'
4
5 . ./lib-git-svn.sh
6
7 -test_dump() {
8 - label=$1
9 - dump=$2
10 - test_expect_success "$dump" '
11 - svnadmin create "$label-svn" &&
12 - svnadmin load "$label-svn" < "$TEST_DIRECTORY/$dump" &&
13 - svn_cmd export "file://$PWD/$label-svn" "$label-svnco" &&
14 - git init "$label-git" &&
15 - test-svn-fe "$TEST_DIRECTORY/$dump" >"$label.fe" &&
16 - (
17 - cd "$label-git" &&
18 - git fast-import < ../"$label.fe"
19 - ) &&
20 - (
21 - cd "$label-svnco" &&
22 - git init &&
23 - git add . &&
24 - git fetch "../$label-git" master &&
25 - git diff --exit-code FETCH_HEAD
26 - )
27 - '
7 +reinit_git () {
8 + rm -fr .git &&
9 + git init
10 }
11
30 -test_dump simple t9135/svn.dump
12 +>empty
13 +
14 +test_expect_success 'empty dump' '
15 + reinit_git &&
16 + echo "SVN-fs-dump-format-version: 2" >input &&
17 + test-svn-fe input >stream &&
18 + git fast-import <stream
19 +'
20 +
21 +test_expect_success 'v3 dumps not supported' '
22 + reinit_git &&
23 + echo "SVN-fs-dump-format-version: 3" >input &&
24 + test_must_fail test-svn-fe input >stream &&
25 + test_cmp empty stream
26 +'
27 +
28 +test_expect_success 't9135/svn.dump' '
29 + svnadmin create simple-svn &&
30 + svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
31 + svn_cmd export "file://$PWD/simple-svn" simple-svnco &&
32 + git init simple-git &&
33 + test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe &&
34 + (
35 + cd simple-git &&
36 + git fast-import <../simple.fe
37 + ) &&
38 + (
39 + cd simple-svnco &&
40 + git init &&
41 + git add . &&
42 + git fetch ../simple-git master &&
43 + git diff --exit-code FETCH_HEAD
44 + )
45 +'
46
47 test_done
vcs-svn/svndump.c
+10 -3
@@ -51,14 +51,14 @@ static struct {
51 } rev_ctx;
52
53 static struct {
54 - uint32_t uuid, url;
54 + uint32_t version, uuid, url;
55 } dump_ctx;
56
57 static struct {
58 uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid,
59 revision_number, node_path, node_kind, node_action,
60 node_copyfrom_path, node_copyfrom_rev, text_content_length,
61 - prop_content_length, content_length;
61 + prop_content_length, content_length, svn_fs_dump_format_version;
62 } keys;
63
64 static void reset_node_ctx(char *fname)
@@ -85,6 +85,7 @@ static void reset_rev_ctx(uint32_t revision)
85 static void reset_dump_ctx(uint32_t url)
86 {
87 dump_ctx.url = url;
88 + dump_ctx.version = 1;
89 dump_ctx.uuid = ~0;
90 }
91
@@ -105,6 +106,7 @@ static void init_keys(void)
106 keys.text_content_length = pool_intern("Text-content-length");
107 keys.prop_content_length = pool_intern("Prop-content-length");
108 keys.content_length = pool_intern("Content-length");
109 + keys.svn_fs_dump_format_version = pool_intern("SVN-fs-dump-format-version");
110 }
111
112 static void read_props(void)
@@ -206,7 +208,12 @@ void svndump_read(const char *url)
208 *val++ = '\0';
209 key = pool_intern(t);
210
209 - if (key == keys.uuid) {
211 + if (key == keys.svn_fs_dump_format_version) {
212 + dump_ctx.version = atoi(val);
213 + if (dump_ctx.version > 2)
214 + die("expected svn dump format version <= 2, found %d",
215 + dump_ctx.version);
216 + } else if (key == keys.uuid) {
217 dump_ctx.uuid = pool_intern(val);
218 } else if (key == keys.revision_number) {
219 if (active_ctx == NODE_CTX)