From: Junio C Hamano <gitster@pobox.com>
To: karthik nayak <karthik.188@gmail.com>
Cc: Git List <git@vger.kernel.org>, Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH v10 0/4] cat-file: add support for "-allow-unknown-type"
Date: Mon, 04 May 2015 13:57:51 -0700 [thread overview]
Message-ID: <xmqqioc8rrg0.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <55477478.9010406@gmail.com> (karthik nayak's message of "Mon, 04 May 2015 19:00:32 +0530")
karthik nayak <karthik.188@gmail.com> writes:
>> @@ -1579,7 +1578,6 @@ static int unpack_sha1_heade
>> if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
>> return 0;
>>
>> - strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
> Ok this works, weird, I test before sending patches, anyways getting
> to the point of discussion, shouldn't we have add the buf, since we
> did inflate once, before doing inflate again?
+static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
+ unsigned long mapsize, void *buffer,
+ unsigned long bufsiz, struct strbuf *header)
+{
+ unsigned char *cp;
+ int status;
+
+ status = unpack_sha1_header(stream, map, mapsize, buffer, bufsiz);
Here, buffer..stream->next_out contains the inflated result
+ /*
+ * Check if entire header is unpacked in the first iteration.
+ */
+ if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
+ return 0;
+
+ strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
... and that is copied to header.buf ...
+ do {
+ status = git_inflate(stream, 0);
... and then we inflate further into where?
It inflates to stream->next_out and then advances the pointer
+ strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
... and then the same buffer..stream->next_out (whose early part
already holds the result from the initial inflation) is appended
to header.
+ if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
+ return 0;
+ stream->next_out = buffer;
+ stream->avail_out = bufsiz;
I think my squash is wrong. The initial inflate must have filled
buffer[0..bufsiz] without any NULs, leaving stream->next_out at the
end of the buffer, and subsequent git_inflate() it will clobber
beyond the tail of the buffer.
It should have been more like this, I think.
diff --git a/sha1_file.c b/sha1_file.c
index f65bf90..37e6f2c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1568,7 +1568,6 @@ static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
unsigned long mapsize, void *buffer,
unsigned long bufsiz, struct strbuf *header)
{
- unsigned char *cp;
int status;
status = unpack_sha1_header(stream, map, mapsize, buffer, bufsiz);
@@ -1579,7 +1578,15 @@ static int unpack_sha1_header_to_strbuf(git_zstream *stream, unsigned char *map,
if (memchr(buffer, '\0', stream->next_out - (unsigned char *)buffer))
return 0;
+ /*
+ * buffer[0..bufsiz] was not large enough. Copy the partial
+ * result out to header, and then append the result of further
+ * reading the stream.
+ */
strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
+ stream->next_out = buffer;
+ stream->avail_out = bufsiz;
+
do {
status = git_inflate(stream, 0);
strbuf_add(header, buffer, stream->next_out - (unsigned char *)buffer);
prev parent reply other threads:[~2015-05-04 20:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-03 14:28 [PATCH v10 0/4] cat-file: add support for "-allow-unknown-type" karthik nayak
2015-05-03 14:29 ` [PATCH v10 1/4] sha1_file: support reading from a loose object of unknown type Karthik Nayak
2015-05-03 14:30 ` [PATCH v10 2/4] cat-file: make the options mutually exclusive Karthik Nayak
2015-05-03 14:30 ` [PATCH v10 3/4] cat-file: teach cat-file a '--allow-unknown-type' option Karthik Nayak
2015-05-05 1:29 ` Eric Sunshine
2015-05-03 14:30 ` [PATCH v10 4/4] t1006: add tests for git cat-file --allow-unknown-type Karthik Nayak
2015-05-05 1:33 ` Eric Sunshine
2015-05-05 2:23 ` karthik nayak
2015-05-06 4:37 ` Junio C Hamano
2015-05-04 23:34 ` [PATCH v10 1/4] sha1_file: support reading from a loose object of unknown type Eric Sunshine
2015-05-05 2:21 ` karthik nayak
2015-05-04 0:10 ` [PATCH v10 0/4] cat-file: add support for "-allow-unknown-type" Junio C Hamano
2015-05-04 0:14 ` Junio C Hamano
2015-05-04 2:55 ` Eric Sunshine
2015-05-04 3:30 ` Eric Sunshine
2015-05-04 13:31 ` karthik nayak
2015-05-06 13:37 ` karthik nayak
2015-05-06 17:16 ` Junio C Hamano
2015-05-07 3:34 ` Karthik Nayak
2015-05-07 18:35 ` Junio C Hamano
2015-05-04 13:30 ` karthik nayak
2015-05-04 20:57 ` Junio C Hamano [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqioc8rrg0.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=sunshine@sunshineco.com \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.