From c2e032a21d23e1a6e4b4dfa5ca5b0f5e891a07e6 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Sun, 10 Oct 2010 21:58:00 -0500 Subject: [PATCH] vcs-svn: Learn to check for SVN\0 magic The magic number of svn deltas is SVN followed by a null byte. An alternative format (with compressed text) uses magic number SVN\1, but that is deprecated in favor of compressing the deltas as a whole as far as I can tell. Signed-off-by: Jonathan Nieder --- svndiff.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/svndiff.c b/svndiff.c index b3761ac..36d2b30 100644 --- a/svndiff.c +++ b/svndiff.c @@ -11,6 +11,7 @@ * * See http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff. * + * svndiff0 ::= 'SVN\0' window window*; * int ::= highdigit* lowdigit; * highdigit ::= # binary 1000 0000 OR-ed with 7 bit value; * lowdigit ::= # 7 bit value; @@ -20,6 +21,23 @@ #define VLI_DIGIT_MASK 0x7f #define VLI_BITS_PER_DIGIT 7 +static int read_magic(struct line_buffer *in, off_t *len) +{ + static const char magic[] = {'S', 'V', 'N', '\0'}; + struct strbuf sb = STRBUF_INIT; + if (*len < sizeof(magic)) + return error("Invalid delta: no file type header"); + buffer_read_binary(&sb, sizeof(magic), in); + if (sb.len != sizeof(magic)) + return error("Invalid delta: no file type header"); + if (memcmp(sb.buf, magic, sizeof(magic))) + return error("Unrecognized file type %.*s", + (int) sizeof(magic), sb.buf); + *len -= sizeof(magic); + strbuf_release(&sb); + return 0; +} + static int read_int(struct line_buffer *in, uintmax_t *result, off_t *len) { off_t sz = *len; -- 2.11.4.GIT