git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git am with MIME

From
Jeff King <peff@peff.net>
Date
Aug 19, 2008, 17:07 UTC
Message-ID
<20080819170731.GA2424@coredump.intra.peff.net>
In-Reply-To
<48AAEBB6.9070306@gmail.com>
On Tue, Aug 19, 2008 at 05:50:14PM +0200, Lea Wiemann wrote:
Show 7 quoted lines
> $ wcat -q
> 'http://article.gmane.org/gmane.comp.version-control.git/91305/raw' | git am
> fatal: `pos + len' is too far after the end of the buffer
> $
> 
> It seems to be because of the (unusual?) way the patch uses MIME.  Just
> wanted to post this so it doesn't get lost.

It's the From header actually. The patch below should fix it (though it sure makes that line of code ugly -- improvements are welcome).

-- >8 -- mailinfo: avoid violating strbuf assertion

In handle_from, we calculate the end boundary of a section to remove from a strbuf using strcspn like this:

  el = strcspn(buf, set_of_end_boundaries);
  strbuf_remove(&sb, start, el + 1);

This works fine if "el" is the offset of the boundary character, meaning we remove that character. But if the end boundary didn't match (that is, we hit the end of the string as the boundary instead) then we want just "el".

This manifested itself when we got a 'From' header that had
just an email address with nothing else in it (the end of
the string was the end of the address, rather than, e.g., a
trailing '>' character).
---
 builtin-mailinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 26d3e5d..e890f7a 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -107,7 +107,7 @@ static void handle_from(const struct strbuf *from)
 	el = strcspn(at, " \n\t\r\v\f>");
 	strbuf_reset(&email);
 	strbuf_add(&email, at, el);
-	strbuf_remove(&f, at - f.buf, el + 1);
+	strbuf_remove(&f, at - f.buf, el + (at[el] ? 1 : 0));
 
 	/* The remainder is name.  It could be "John Doe <john.doe@xz>"
 	 * or "john.doe@xz (John Doe)", but we have removed the
-- 
1.6.0.96.g2fad1.dirty
Previous: Lea WiemannNext: Alex Riesen
Message 2 of 6 in “git am with MIME”
  1. Lea WiemannAug 19, 2008
  2. Jeff KingAug 19, 2008
  3. Alex RiesenAug 20, 2008
  4. Jeff KingAug 20, 2008
  5. Eric RaibleAug 21, 2008
  6. Alex RiesenAug 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.