Subject: "git fast-import" crashes parsing output from "fossil export --git"

From: SZEDER Gábor <[email-masked]>
Date: Mon, 29 Jan 2018 18:11:27 +0100

> "git fast-import" fails while trying to import the latest "Fossil"
> fossil-sources (it dog-foods its own source-code). Namely, the below
> pasted commands caused the crash report below them (I've trimmed
> irrelevant noise from the report for brevity). One of the tests
> included in Fossil uses example-files to test its handling of
> filenames with special characters - in this case an embedded newline
> in "abc[NEWLINE]def.txt" - and "git fast-import" causes the second
> part of that filename (post-newline) to spill over as the "command" on
> the next line of its input when transforming the "fossil export"
> output into usable input. Considering git can handle such filenames, I
> guess "git fast-import" not handling them counts as a bug - unless a
> design-decision was made to not be as rigorous for the sake of
> simplicity in the import protocol? Or is "fossil export" perhaps
> outputting the filename incorrectly for the "fast-import" protocol
> (maybe it needs some kind of quoting)?
> 
> * Commands which cause the crash:
> ----8<----
> fossil clone https://www.fossil-scm.org/xfer fossil.fossil
> git init fossil-git
> cd fossil-git
> fossil export --git ../fossil.fossil | git fast-import
> ----8<----
> 
> * The part of "fossil export" output which breaks "git fast-import":
> ----8<----
> ...
> 
> commit refs/heads/test-ticket-d17d6e5b17
> mark :26782
> committer jan.nijtmans <jan.nijtmans> 1353531216 +0000
> data 82
> Just commit some weird filenames, even one with a newline in it, to
> test the code.
> from :26779
> M 100644 :427 :abc
> M 100644 :10049 abc
> def.txt

A path like this must be quoted.  Quoting from 'git fast-import'
manpage:

  A <path> string must use UNIX-style directory separators (forward
  slash /), may contain any byte other than LF, and must not start
  with double quote (").

  A path can use C-style string quoting; this is accepted in all
  cases and mandatory if the filename starts with double quote or
  contains LF. In C-style quoting, the complete name should be
  surrounded with double quotes, and any LF, backslash, or double
  quote characters must be escaped by preceding them with a backslash
  (e.g., "path/with\n, \\ and \" in it").