git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH np/pack-v4] index-pack: tighten object type check based on pack version
@ 2013-09-18 12:25 Nguyễn Thái Ngọc Duy
  2013-09-18 14:39 ` Nicolas Pitre
  0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2013-09-18 12:25 UTC (permalink / raw)
  To: Nicolas Pitre; +Cc: git, Nguyễn Thái Ngọc Duy

In pack version 4, ref-delta technically could be used to compress any
objects including commits and trees (both canonical and v4). But it
does not make sense to do so. It can only lead to performance
degradation. Catch those packers.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I could now verify that pack-objects does not compress commits nor
 trees using ref-delta in v4. But perhaps these are a bit too strict?
 Maybe downgrade from die() to warning() and still accept the pack?

 builtin/index-pack.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index fbf97f0..e4ecf69 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -788,6 +788,12 @@ static void *unpack_raw_entry(struct object_entry *obj,
 	case OBJ_BLOB:
 	case OBJ_TAG:
 		break;
+
+	/*
+	 * OBJ_PV4_* are all greater than 7, which is the limit of
+	 * field "type" in pack v2. So we do not really need 'if
+	 * (!packv4) die("wrong type");' here.
+	 */
 	case OBJ_PV4_COMMIT:
 		obj->real_type = OBJ_COMMIT;
 		break;
@@ -1288,6 +1294,16 @@ static void resolve_delta(struct object_entry *delta_obj,
 	hash_sha1_file(result->data, result->size,
 		       typename(delta_obj->real_type), delta_obj->idx.sha1);
 	check_against_sha1table(delta_obj->idx.sha1);
+	if (packv4 &&
+	    delta_obj->type == OBJ_REF_DELTA &&
+	    delta_obj->real_type == OBJ_TREE)
+		bad_object(delta_obj->idx.offset,
+			   _("ref-delta on a tree is not supported in pack version 4"));
+	if (packv4 &&
+	    delta_obj->type == OBJ_REF_DELTA &&
+	    delta_obj->real_type == OBJ_COMMIT)
+		bad_object(delta_obj->idx.offset,
+			   _("ref-delta on a commit is not supported in pack version 4"));
 	sha1_object(result->data, NULL, result->size, delta_obj->real_type,
 		    delta_obj->idx.sha1);
 	counter_lock();
-- 
1.8.2.83.gc99314b

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH np/pack-v4] index-pack: tighten object type check based on pack version
  2013-09-18 12:25 [PATCH np/pack-v4] index-pack: tighten object type check based on pack version Nguyễn Thái Ngọc Duy
@ 2013-09-18 14:39 ` Nicolas Pitre
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pitre @ 2013-09-18 14:39 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1015 bytes --]

On Wed, 18 Sep 2013, Nguyễn Thái Ngọc Duy wrote:

> In pack version 4, ref-delta technically could be used to compress any
> objects including commits and trees (both canonical and v4). But it
> does not make sense to do so. It can only lead to performance
> degradation. Catch those packers.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  I could now verify that pack-objects does not compress commits nor
>  trees using ref-delta in v4. But perhaps these are a bit too strict?
>  Maybe downgrade from die() to warning() and still accept the pack?

Even then...  There is a difference between an "invalid" pack and a 
"suboptimal" one.  I don't think we should complain when presented with 
suboptimal encoding if it is still valid and there is no problem 
actually processing the data correctly.  You never know when this 
alternative encoding, even if suboptimal, might be handy.

Robustness principle: Be conservative in what you send, be liberal in 
what you accept.


Nicolas

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-09-18 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-18 12:25 [PATCH np/pack-v4] index-pack: tighten object type check based on pack version Nguyễn Thái Ngọc Duy
2013-09-18 14:39 ` Nicolas Pitre

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).