Skip to content

Commit c7dbf35

Browse files
jrngitster
authored andcommitted
vcs-svn: More dump format sanity checks
Node-action: change is not appropriate when switching between file and directory or adding a new file. Current svn-fe silently accepts such nodes and the resulting tree has missing files in the "changed when meant to add" case. Node-action: add requires some content (text or directory); there is no such thing as an "intent to add" node in svn dumps. Current svn-fe accepts such contentless adds but produces an invalid fast-import stream that refers to nonexistent mark :0 in response. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 414e569 commit c7dbf35

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

t/t9010-svn-fe.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,27 @@ test_expect_success 'node without action' '
272272
test_must_fail test-svn-fe inaction.dump
273273
'
274274

275+
test_expect_success 'action: add node without text' '
276+
cat >textless.dump <<-\EOF &&
277+
SVN-fs-dump-format-version: 3
278+
279+
Revision-number: 1
280+
Prop-content-length: 10
281+
Content-length: 10
282+
283+
PROPS-END
284+
285+
Node-path: textless
286+
Node-kind: file
287+
Node-action: add
288+
Prop-content-length: 10
289+
Content-length: 10
290+
291+
PROPS-END
292+
EOF
293+
test_must_fail test-svn-fe textless.dump
294+
'
295+
275296
test_expect_failure 'change file mode but keep old content' '
276297
reinit_git &&
277298
cat >expect <<-\EOF &&

vcs-svn/svndump.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,22 @@ static void handle_node(void)
181181
if (mark && type == REPO_MODE_DIR)
182182
die("invalid dump: directories cannot have text attached");
183183

184-
if (node_ctx.action == NODEACT_CHANGE)
185-
node_ctx.type = repo_modify_path(node_ctx.dst, 0, mark);
186-
else if (node_ctx.action == NODEACT_ADD)
184+
if (node_ctx.action == NODEACT_CHANGE) {
185+
uint32_t mode = repo_modify_path(node_ctx.dst, 0, mark);
186+
if (!mode)
187+
die("invalid dump: path to be modified is missing");
188+
if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR)
189+
die("invalid dump: cannot modify a directory into a file");
190+
if (mode != REPO_MODE_DIR && type == REPO_MODE_DIR)
191+
die("invalid dump: cannot modify a file into a directory");
192+
node_ctx.type = mode;
193+
} else if (node_ctx.action == NODEACT_ADD) {
194+
if (!mark && type != REPO_MODE_DIR)
195+
die("invalid dump: adds node without text");
187196
repo_add(node_ctx.dst, type, mark);
188-
else
197+
} else {
189198
die("invalid dump: Node-path block lacks Node-action");
199+
}
190200

191201
if (have_props) {
192202
const uint32_t old_mode = node_ctx.type;

0 commit comments

Comments
 (0)