git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: <git@vger.kernel.org>
Cc: Michael Haggerty <mhagger@alum.mit.edu>,
	Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>,
	David Barr <david.barr@cordelta.com>,
	Elijah Newren <newren@gmail.com>
Subject: [RFC PATCH 0/5] Fix some fast-import parsing issues
Date: Wed, 20 Feb 2019 14:58:41 -0800	[thread overview]
Message-ID: <20190220225846.10658-1-newren@gmail.com> (raw)

I found a few issues with parsing in fast-import (dating back to
git-2.6.0).  I was thrown off track for a while by the fact that the
.git/fast_import_crash_$PID file erroneously claimed that the
penultimate command it read was somehow truncated; e.g. for input of
the form:

    commit refs/heads/master
    mark :1
    author Full Name <user@organization.tld> 1000000000 +0100
    committer Full Name <user@organization.tld> 1000000000 +0100
    data 53
    Commit message for intentionally empty orphan commit
    get-mark :1
    
the crash file was reporting

    Most Recent Commands Before Crash
    ---------------------------------
      commit refs/heads/master
      mark :1
      author Full Name <user@organization.tld> 1000000000 +0100
      committer Full Name <user@organization.tld> 1000000000 +0100
      data 53
    * get-mark :1
    
In other words, it dropped the commit message line entirely, which
made me wonder if I was having weird buffering or flushing issues
until I was able to narrow it down to the simple testcase above and
could duplicate with
    cat seven-line-test-file | git fast-import
I don't know if there are other ways to get fast-import to give a
corrupted "Most Recent Commands Before Crash" report, but this one
doesn't trigger after my other fixes below.

Switching gears from the bad reporting to the original parsing bug
though, it is clear fast-import somehow mishandled get-mark directives
after empty orphan commits.  Digging into it, I think it was caused by
following a precedent set by a somewhat unsafe implementation of
trying to allow cat-blob directives to appear in the middle of a
commit.  My spelunking showed the following commits seemed to be the
most relevant as to how we got to the current state:

    777f80d7429b ("fast-import: Allow cat-blob requests at arbitrary
                 points in stream", 2010-11-28)
    8dc6a373d201 ("fast-import: add 'ls' command", 2010-12-02)
    97313bef2a16 ("fast-import: use skip_prefix for parsing input",
                  2014-06-18)
    28c7b1f7b7b7 ("fast-import: add a get-mark command", 2015-07-01)

I've cc'ed the relevant folks, and have a few patches that fix the
issue and I think make the parser more robust against future issues in
a way that I think is safe enough for backward compatibility, but
"backward compatible enough" might concern some folks; if so, please
take a look at patches 4 and 5.

Elijah Newren (5):
  t9300: demonstrate bug with get-mark and empty orphan commits
  git-fast-import.txt: fix wording about where ls command can appear
  fast-import: check most prominent commands first
  fast-import: only allow cat-blob requests where it makes sense
  fast-import: fix erroneous handling of get-mark with empty orphan
    commits

 Documentation/git-fast-import.txt | 22 +++++++++---------
 fast-import.c                     | 31 ++++++++++++++------------
 t/t9300-fast-import.sh            | 37 +++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 24 deletions(-)

-- 
2.21.0.rc2.5.g8f70af2367

             reply	other threads:[~2019-02-20 22:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 22:58 Elijah Newren [this message]
2019-02-20 22:58 ` [RFC PATCH 1/5] t9300: demonstrate bug with get-mark and empty orphan commits Elijah Newren
2019-02-20 22:58 ` [RFC PATCH 2/5] git-fast-import.txt: fix wording about where ls command can appear Elijah Newren
2019-02-20 22:58 ` [RFC PATCH 3/5] fast-import: check most prominent commands first Elijah Newren
2019-02-20 22:58 ` [RFC PATCH 4/5] fast-import: only allow cat-blob requests where it makes sense Elijah Newren
2019-02-20 22:58 ` [RFC PATCH 5/5] fast-import: fix erroneous handling of get-mark with empty orphan commits Elijah Newren
2019-03-08 16:53 ` [RFC PATCH 0/5] Fix some fast-import parsing issues Elijah Newren
2019-04-01 10:44   ` Junio C Hamano
2019-04-01 15:52     ` Elijah Newren
2019-04-01 16:00 ` [PATCH v2 " Elijah Newren
2019-04-01 16:00   ` [PATCH v2 1/5] t9300: demonstrate bug with get-mark and empty orphan commits Elijah Newren
2019-04-01 16:00   ` [PATCH v2 2/5] git-fast-import.txt: fix wording about where ls command can appear Elijah Newren
2019-04-01 16:00   ` [PATCH v2 3/5] fast-import: check most prominent commands first Elijah Newren
2019-04-01 16:00   ` [PATCH v2 4/5] fast-import: only allow cat-blob requests where it makes sense Elijah Newren
2019-04-01 16:00   ` [PATCH v2 5/5] fast-import: fix erroneous handling of get-mark with empty orphan commits Elijah Newren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190220225846.10658-1-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=david.barr@cordelta.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=mhagger@alum.mit.edu \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).