Skip to content

Commit b3e5bce

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03276d9 commit b3e5bce

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

t/t9010-svn-fe.sh

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,44 @@ test_description='check svn dumpfile importer'
44

55
. ./lib-git-svn.sh
66

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
2810
}
2911

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+
'
3146

3247
test_done

vcs-svn/svndump.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ static struct {
5151
} rev_ctx;
5252

5353
static struct {
54-
uint32_t uuid, url;
54+
uint32_t version, uuid, url;
5555
} dump_ctx;
5656

5757
static struct {
5858
uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid,
5959
revision_number, node_path, node_kind, node_action,
6060
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;
6262
} keys;
6363

6464
static void reset_node_ctx(char *fname)
@@ -85,6 +85,7 @@ static void reset_rev_ctx(uint32_t revision)
8585
static void reset_dump_ctx(uint32_t url)
8686
{
8787
dump_ctx.url = url;
88+
dump_ctx.version = 1;
8889
dump_ctx.uuid = ~0;
8990
}
9091

@@ -105,6 +106,7 @@ static void init_keys(void)
105106
keys.text_content_length = pool_intern("Text-content-length");
106107
keys.prop_content_length = pool_intern("Prop-content-length");
107108
keys.content_length = pool_intern("Content-length");
109+
keys.svn_fs_dump_format_version = pool_intern("SVN-fs-dump-format-version");
108110
}
109111

110112
static void read_props(void)
@@ -206,7 +208,12 @@ void svndump_read(const char *url)
206208
*val++ = '\0';
207209
key = pool_intern(t);
208210

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) {
210217
dump_ctx.uuid = pool_intern(val);
211218
} else if (key == keys.revision_number) {
212219
if (active_ctx == NODE_CTX)

0 commit comments

Comments
 (0)