{"thread":{"id":"46574","subject":"[PATCH] Add overflow check to get_delta_hdr_size","startedAt":"2017-08-12T08:47:30Z","lastAt":"2017-08-14T16:56:06Z","messageCount":3,"participants":["Martin Koegler","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"326196","messageId":"1502522838-12581-1-git-send-email-martin@mail.zuhause","threadId":"46574","inReplyTo":null,"subject":"[PATCH] Add overflow check to get_delta_hdr_size","fromName":"Martin Koegler","fromEmail":"martin.koegler@chello.at","sentAt":"2017-08-12T07:27:18Z","receivedAt":"2017-08-12T08:47:30Z","isPatch":true,"sender":{"key":"martin.koegler@chello.at","avatar":"https://avatars.githubusercontent.com/u/1859030?v=4"},"body":"From: Martin Koegler <martin.koegler@chello.at>\n\nSigned-off-by: Martin Koegler <martin.koegler@chello.at>\n---\nApplies on top of my size_t series\n\nI'm not sure, if die or error is better.\n\n delta.h | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/delta.h b/delta.h\nindex 2df0f55..18a4983 100644\n--- a/delta.h\n+++ b/delta.h\n@@ -96,6 +96,11 @@ static inline size_t get_delta_hdr_size(const unsigned char **datap,\n \t\tcmd = *data++;\n \t\tsize |= (cmd & 0x7f) << i;\n \t\ti += 7;\n+\t\tif (bitsizeof(size_t) <= i) {\n+\t\t\terror(\"too large object size\");\n+\t\t\tsize = 0;\n+\t\t\tbreak;\n+\t\t}\n \t} while (cmd & 0x80 && data < top);\n \t*datap = data;\n \treturn size;\n-- \n2.1.4\n\n"},{"id":"326277","messageId":"xmqqlgmmw0lc.fsf@gitster.mtv.corp.google.com","threadId":"46574","inReplyTo":"1502522838-12581-1-git-send-email-martin@mail.zuhause","subject":"Re: [PATCH] Add overflow check to get_delta_hdr_size","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-14T16:55:27Z","receivedAt":"2017-08-14T16:55:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Koegler <martin.koegler@chello.at> writes:\n\n> From: Martin Koegler <martin.koegler@chello.at>\n>\n> Signed-off-by: Martin Koegler <martin.koegler@chello.at>\n> ---\n> Applies on top of my size_t series\n>\n> I'm not sure, if die or error is better.\n\nAs there is no fallback when we hit it, die would be sufficient; the\nonly thing the callers of this helper, or their callers, could do is\nas a reaction to an error return from here would be to die themselves,\nI would think.\n\n>\n>  delta.h | 5 +++++\n>  1 file changed, 5 insertions(+)\n>\n> diff --git a/delta.h b/delta.h\n> index 2df0f55..18a4983 100644\n> --- a/delta.h\n> +++ b/delta.h\n> @@ -96,6 +96,11 @@ static inline size_t get_delta_hdr_size(const unsigned char **datap,\n>  \t\tcmd = *data++;\n>  \t\tsize |= (cmd & 0x7f) << i;\n>  \t\ti += 7;\n> +\t\tif (bitsizeof(size_t) <= i) {\n> +\t\t\terror(\"too large object size\");\n> +\t\t\tsize = 0;\n> +\t\t\tbreak;\n> +\t\t}\n>  \t} while (cmd & 0x80 && data < top);\n>  \t*datap = data;\n>  \treturn size;\n"},{"id":"326278","messageId":"xmqqk226w0kf.fsf@gitster.mtv.corp.google.com","threadId":"46574","inReplyTo":"1502522838-12581-1-git-send-email-martin@mail.zuhause","subject":"Re: [PATCH] Add overflow check to get_delta_hdr_size","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-14T16:56:00Z","receivedAt":"2017-08-14T16:56:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Koegler <martin.koegler@chello.at> writes:\n\n> From: Martin Koegler <martin.koegler@chello.at>\n>\n> Signed-off-by: Martin Koegler <martin.koegler@chello.at>\n> ---\n> Applies on top of my size_t series\n>\n> I'm not sure, if die or error is better.\n\nAs there is no fallback when we hit it, die would be sufficient; the\nonly thing the callers of this helper, or their callers, could do is\nas a reaction to an error return from here would be to die themselves,\nI would think.\n\n\n\n\n>  delta.h | 5 +++++\n>  1 file changed, 5 insertions(+)\n>\n> diff --git a/delta.h b/delta.h\n> index 2df0f55..18a4983 100644\n> --- a/delta.h\n> +++ b/delta.h\n> @@ -96,6 +96,11 @@ static inline size_t get_delta_hdr_size(const unsigned char **datap,\n>  \t\tcmd = *data++;\n>  \t\tsize |= (cmd & 0x7f) << i;\n>  \t\ti += 7;\n> +\t\tif (bitsizeof(size_t) <= i) {\n> +\t\t\terror(\"too large object size\");\n> +\t\t\tsize = 0;\n> +\t\t\tbreak;\n> +\t\t}\n>  \t} while (cmd & 0x80 && data < top);\n>  \t*datap = data;\n>  \treturn size;\n"}]}