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

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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Nov 19, 2010 at 18:53 UTC c7dbf35e91cffbc326078d0c0470662f6422150d
2 files changed +35 -4
t/t9010-svn-fe.sh
+21
@@ -272,6 +272,27 @@ test_expect_success 'node without action' '
272 test_must_fail test-svn-fe inaction.dump
273 '
274
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 +
296 test_expect_failure 'change file mode but keep old content' '
297 reinit_git &&
298 cat >expect <<-\EOF &&
vcs-svn/svndump.c
+14 -4
@@ -181,12 +181,22 @@ static void handle_node(void)
181 if (mark && type == REPO_MODE_DIR)
182 die("invalid dump: directories cannot have text attached");
183
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");
196 repo_add(node_ctx.dst, type, mark);
188 - else
197 + } else {
198 die("invalid dump: Node-path block lacks Node-action");
199 + }
200
201 if (have_props) {
202 const uint32_t old_mode = node_ctx.type;