From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <johannes.schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/6] Accept object data in the fsck_object() function
Date: Thu, 28 Aug 2014 13:47:52 -0700 [thread overview]
Message-ID: <xmqqvbpc8hon.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.1.00.1408281646400.990@s15462909.onlinehome-server.info> (Johannes Schindelin's message of "Thu, 28 Aug 2014 16:46:42 +0200 (CEST)")
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> When fsck'ing an incoming pack, we need to fsck objects that cannot be
> read via read_sha1_file() because they are not local yet (and might even
> be rejected if transfer.fsckobjects is set to 'true').
>
> For commits, there is a hack in place: we basically cache commit
> objects' buffers anyway, but the same is not true, say, for tag objects.
>
> By refactoring fsck_object() to take the object buffer and size as
> optional arguments -- optional, because we still fall back to the
> previous method to look at the cached commit objects if the caller
> passes NULL -- we prepare the machinery for the upcoming handling of tag
> objects.
>
> The assumption that such buffers are inherently NUL terminated is now
> wrong, of course, hence we pass the size of the buffer so that we can
> add a sanity check later, to prevent running past the end of the buffer.
A nice side effect may be that we can now check (and perhaps warn) a
commit buffer with a NUL inside, perhaps? I am not suggesting to
add such a check to this series, but mentioning the possibilty here
may have a merit.
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> builtin/fsck.c | 2 +-
> builtin/index-pack.c | 3 ++-
> builtin/unpack-objects.c | 14 ++++++++++----
> fsck.c | 24 +++++++++++++++---------
> fsck.h | 4 +++-
> 5 files changed, 31 insertions(+), 16 deletions(-)
>
> diff --git a/builtin/fsck.c b/builtin/fsck.c
> index d42a27d..d9f4e6e 100644
> --- a/builtin/fsck.c
> +++ b/builtin/fsck.c
> @@ -298,7 +298,7 @@ static int fsck_obj(struct object *obj)
>
> if (fsck_walk(obj, mark_used, NULL))
> objerror(obj, "broken links");
> - if (fsck_object(obj, check_strict, fsck_error_func))
> + if (fsck_object(obj, NULL, 0, check_strict, fsck_error_func))
> return -1;
>
> if (obj->type == OBJ_TREE) {
> diff --git a/builtin/index-pack.c b/builtin/index-pack.c
> index 5568a5b..f2465ff 100644
> --- a/builtin/index-pack.c
> +++ b/builtin/index-pack.c
> @@ -773,7 +773,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
> if (!obj)
> die(_("invalid %s"), typename(type));
> if (do_fsck_object &&
> - fsck_object(obj, 1, fsck_error_function))
> + fsck_object(obj, buf, size, 1,
> + fsck_error_function))
> die(_("Error in object"));
> if (fsck_walk(obj, mark_link, NULL))
> die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
> diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
> index 99cde45..855d94b 100644
> --- a/builtin/unpack-objects.c
> +++ b/builtin/unpack-objects.c
> @@ -164,10 +164,10 @@ static unsigned nr_objects;
> * Called only from check_object() after it verified this object
> * is Ok.
> */
> -static void write_cached_object(struct object *obj)
> +static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
> {
> unsigned char sha1[20];
> - struct obj_buffer *obj_buf = lookup_object_buffer(obj);
> +
> if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0)
> die("failed to write object %s", sha1_to_hex(obj->sha1));
> obj->flags |= FLAG_WRITTEN;
> @@ -180,6 +180,8 @@ static void write_cached_object(struct object *obj)
> */
> static int check_object(struct object *obj, int type, void *data)
> {
> + struct obj_buffer *obj_buf;
> +
> if (!obj)
> return 1;
>
> @@ -198,11 +200,15 @@ static int check_object(struct object *obj, int type, void *data)
> return 0;
> }
>
> - if (fsck_object(obj, 1, fsck_error_function))
> + obj_buf = lookup_object_buffer(obj);
> + if (!obj_buf)
> + die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
> + if (fsck_object(obj, obj_buf->buffer, obj_buf->size, 1,
> + fsck_error_function))
> die("Error in object");
> if (fsck_walk(obj, check_object, NULL))
> die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
> - write_cached_object(obj);
> + write_cached_object(obj, obj_buf);
> return 0;
> }
>
> diff --git a/fsck.c b/fsck.c
> index 56156ff..dd77628 100644
> --- a/fsck.c
> +++ b/fsck.c
> @@ -277,7 +277,7 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f
> }
>
> static int fsck_commit_buffer(struct commit *commit, const char *buffer,
> - fsck_error error_func)
> + unsigned long size, fsck_error error_func)
> {
> unsigned char tree_sha1[20], sha1[20];
> struct commit_graft *graft;
> @@ -322,15 +322,18 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
> return 0;
> }
>
> -static int fsck_commit(struct commit *commit, fsck_error error_func)
> +static int fsck_commit(struct commit *commit, const char *data,
> + unsigned long size, fsck_error error_func)
> {
> - const char *buffer = get_commit_buffer(commit, NULL);
> - int ret = fsck_commit_buffer(commit, buffer, error_func);
> - unuse_commit_buffer(commit, buffer);
> + const char *buffer = data ? data : get_commit_buffer(commit, &size);
> + int ret = fsck_commit_buffer(commit, buffer, size, error_func);
> + if (!data)
> + unuse_commit_buffer(commit, buffer);
> return ret;
> }
>
> -static int fsck_tag(struct tag *tag, fsck_error error_func)
> +static int fsck_tag(struct tag *tag, const char *data,
> + unsigned long size, fsck_error error_func)
> {
> struct object *tagged = tag->tagged;
>
> @@ -339,7 +342,8 @@ static int fsck_tag(struct tag *tag, fsck_error error_func)
> return 0;
> }
>
> -int fsck_object(struct object *obj, int strict, fsck_error error_func)
> +int fsck_object(struct object *obj, void *data, unsigned long size,
> + int strict, fsck_error error_func)
> {
> if (!obj)
> return error_func(obj, FSCK_ERROR, "no valid object to fsck");
> @@ -349,9 +353,11 @@ int fsck_object(struct object *obj, int strict, fsck_error error_func)
> if (obj->type == OBJ_TREE)
> return fsck_tree((struct tree *) obj, strict, error_func);
> if (obj->type == OBJ_COMMIT)
> - return fsck_commit((struct commit *) obj, error_func);
> + return fsck_commit((struct commit *) obj, (const char *) data,
> + size, error_func);
> if (obj->type == OBJ_TAG)
> - return fsck_tag((struct tag *) obj, error_func);
> + return fsck_tag((struct tag *) obj, (const char *) data,
> + size, error_func);
>
> return error_func(obj, FSCK_ERROR, "unknown type '%d' (internal fsck error)",
> obj->type);
> diff --git a/fsck.h b/fsck.h
> index 1e4f527..d1e6387 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -28,6 +28,8 @@ int fsck_error_function(struct object *obj, int type, const char *fmt, ...);
> * 0 everything OK
> */
> int fsck_walk(struct object *obj, fsck_walk_func walk, void *data);
> -int fsck_object(struct object *obj, int strict, fsck_error error_func);
> +/* If NULL is passed for data, we assume the object is local and read it. */
> +int fsck_object(struct object *obj, void *data, unsigned long size,
> + int strict, fsck_error error_func);
>
> #endif
next prev parent reply other threads:[~2014-08-28 20:48 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-28 14:46 [PATCH 0/6] Improve tag checking in fsck and with transfer.fsckobjects Johannes Schindelin
2014-08-28 14:46 ` [PATCH 1/6] Refactor type_from_string() to avoid die()ing in case of errors Johannes Schindelin
2014-08-28 20:43 ` Junio C Hamano
2014-08-28 14:46 ` [PATCH 2/6] Accept object data in the fsck_object() function Johannes Schindelin
2014-08-28 20:47 ` Junio C Hamano [this message]
2014-08-29 23:10 ` Jeff King
2014-08-29 23:05 ` Jeff King
2014-08-28 14:46 ` [PATCH 3/6] Make sure fsck_commit_buffer() does not run out of the buffer Johannes Schindelin
2014-08-28 20:59 ` Junio C Hamano
2014-08-29 23:27 ` Jeff King
2014-08-28 14:46 ` [PATCH 4/6] fsck: check tag objects' headers Johannes Schindelin
2014-08-28 21:25 ` Junio C Hamano
2014-08-28 21:36 ` Junio C Hamano
2014-08-29 23:46 ` Jeff King
2014-08-31 22:46 ` Junio C Hamano
2014-09-03 22:29 ` Jeff King
2014-09-03 23:14 ` Junio C Hamano
2014-09-04 2:04 ` Jeff King
2014-08-29 23:43 ` Jeff King
2014-09-02 18:41 ` Junio C Hamano
2014-09-03 21:38 ` Jeff King
2014-08-28 14:46 ` [PATCH 5/6] Add regression tests for stricter tag fsck'ing Johannes Schindelin
2014-08-28 14:47 ` [PATCH 6/6] Make sure that index-pack --strict fails upon invalid tag objects Johannes Schindelin
2014-09-10 13:52 ` [PATCH v2 0/6] Improve tag checking in fsck and with transfer.fsckobjects Johannes Schindelin
2014-09-10 13:58 ` Johannes Schindelin
2014-09-10 21:07 ` Junio C Hamano
2014-09-10 21:31 ` Junio C Hamano
2014-09-11 14:20 ` Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 " Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 1/6] Refactor type_from_string() to avoid die()ing in case of errors Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 2/6] Accept object data in the fsck_object() function Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 3/6] Make sure fsck_commit_buffer() does not run out of the buffer Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 4/6] fsck: check tag objects' headers Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 5/6] Add regression tests for stricter tag fsck'ing Johannes Schindelin
2014-09-11 14:26 ` [PATCH v3 6/6] Make sure that index-pack --strict checks tag objects Johannes Schindelin
2014-09-11 17:58 ` Junio C Hamano
2014-09-11 21:16 ` Junio C Hamano
2014-09-11 21:17 ` [PATCH 0/3] hash-object --literally Junio C Hamano
2014-09-11 21:17 ` [PATCH 1/3] hash-object: reduce file-scope statics Junio C Hamano
2014-09-11 21:17 ` [PATCH 2/3] hash-object: pass 'write_object' as a flag Junio C Hamano
2014-09-11 21:17 ` [PATCH 3/3] hash-object: add --literally option Junio C Hamano
2014-09-12 8:04 ` [PATCH v3 6/6] Make sure that index-pack --strict checks tag objects Johannes Schindelin
2014-09-12 8:07 ` [PATCH v4 0/6] Improve tag checking in fsck and with transfer.fsckobjects Johannes Schindelin
2014-09-12 8:07 ` [PATCH v4 1/6] Refactor type_from_string() to avoid die()ing in case of errors Johannes Schindelin
2014-09-12 8:07 ` [PATCH v4 2/6] Accept object data in the fsck_object() function Johannes Schindelin
2014-09-12 8:07 ` [PATCH v4 3/6] Make sure fsck_commit_buffer() does not run out of the buffer Johannes Schindelin
2014-09-12 8:08 ` [PATCH v4 4/6] fsck: check tag objects' headers Johannes Schindelin
2014-09-12 8:08 ` [PATCH v4 5/6] Add regression tests for stricter tag fsck'ing Johannes Schindelin
2014-09-12 8:08 ` [PATCH v4 6/6] Make sure that index-pack --strict checks tag objects Johannes Schindelin
2014-09-12 18:02 ` [PATCH v4 0/6] Improve tag checking in fsck and with transfer.fsckobjects Junio C Hamano
2014-09-13 9:08 ` Johannes Schindelin
[not found] ` <cover.1410356761.git.johannes.schindelin@gmx.de>
2014-09-10 13:52 ` [PATCH v2 1/6] Refactor type_from_string() to avoid die()ing in case of errors Johannes Schindelin
2014-09-10 13:52 ` [PATCH v2 2/6] Accept object data in the fsck_object() function Johannes Schindelin
2014-09-10 13:52 ` [PATCH v2 3/6] Make sure fsck_commit_buffer() does not run out of the buffer Johannes Schindelin
2014-09-10 17:43 ` Junio C Hamano
2014-09-11 11:59 ` Johannes Schindelin
2014-09-11 16:49 ` Junio C Hamano
2014-09-10 20:45 ` Eric Sunshine
2014-09-10 13:53 ` [PATCH v2 4/6] fsck: check tag objects' headers Johannes Schindelin
2014-09-10 17:52 ` Junio C Hamano
2014-09-10 13:53 ` [PATCH v2 5/6] Add regression tests for stricter tag fsck'ing Johannes Schindelin
2014-09-10 17:56 ` Junio C Hamano
2014-09-11 14:15 ` Johannes Schindelin
2014-09-10 13:53 ` [PATCH v2 6/6] Make sure that index-pack --strict fails upon invalid tag objects Johannes Schindelin
2014-09-10 21:54 ` Junio C Hamano
2014-09-11 14:22 ` Johannes Schindelin
2014-09-11 16:50 ` Junio C Hamano
2014-09-11 17:04 ` Johannes Schindelin
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=xmqqvbpc8hon.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
/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 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 NNTP newsgroup(s).