Skip to content

Commit 150f754

Browse files
jrngitster
authored andcommitted
vcs-svn: allow import of > 4GiB files
There is no reason in principle that an svn-format dump would not be able to represent a file whose length does not fit in a 32-bit integer. Use off_t consistently to represent file lengths (in place of using uint32_t in some contexts) so we can handle that. Most svn-fe code is already ready to do that without this patch and passes values of type off_t around. The type mismatch from stragglers was noticed with gcc -Wtype-limits. While at it, tighten the parsing of the Text-content-length field to make sure it is a number and does not overflow, and tighten other overflow checks as that value is passed around and manipulated. Inspired-by: Ramsay Jones <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 173223a commit 150f754

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

vcs-svn/fast_export.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,18 @@ static long apply_delta(off_t len, struct line_buffer *input,
227227
return ret;
228228
}
229229

230-
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input)
230+
void fast_export_data(uint32_t mode, off_t len, struct line_buffer *input)
231231
{
232+
assert(len >= 0);
232233
if (mode == REPO_MODE_LNK) {
233234
/* svn symlink blobs start with "link " */
235+
if (len < 5)
236+
die("invalid dump: symlink too short for \"link\" prefix");
234237
len -= 5;
235238
if (buffer_skip_bytes(input, 5) != 5)
236239
die_short_read(input);
237240
}
238-
printf("data %"PRIu32"\n", len);
241+
printf("data %"PRIuMAX"\n", (uintmax_t) len);
239242
if (buffer_copy_bytes(input, len) != len)
240243
die_short_read(input);
241244
fputc('\n', stdout);
@@ -297,12 +300,12 @@ int fast_export_ls(const char *path, uint32_t *mode, struct strbuf *dataref)
297300

298301
void fast_export_blob_delta(uint32_t mode,
299302
uint32_t old_mode, const char *old_data,
300-
uint32_t len, struct line_buffer *input)
303+
off_t len, struct line_buffer *input)
301304
{
302305
long postimage_len;
303-
if (len > maximum_signed_value_of_type(off_t))
304-
die("enormous delta");
305-
postimage_len = apply_delta((off_t) len, input, old_data, old_mode);
306+
307+
assert(len >= 0);
308+
postimage_len = apply_delta(len, input, old_data, old_mode);
306309
if (mode == REPO_MODE_LNK) {
307310
buffer_skip_bytes(&postimage, strlen("link "));
308311
postimage_len -= strlen("link ");

vcs-svn/fast_export.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ void fast_export_begin_commit(uint32_t revision, const char *author,
1414
const struct strbuf *log, const char *uuid,
1515
const char *url, unsigned long timestamp);
1616
void fast_export_end_commit(uint32_t revision);
17-
void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
17+
void fast_export_data(uint32_t mode, off_t len, struct line_buffer *input);
1818
void fast_export_blob_delta(uint32_t mode,
1919
uint32_t old_mode, const char *old_data,
20-
uint32_t len, struct line_buffer *input);
20+
off_t len, struct line_buffer *input);
2121

2222
/* If there is no such file at that rev, returns -1, errno == ENOENT. */
2323
int fast_export_ls_rev(uint32_t rev, const char *path,

vcs-svn/svndump.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
static struct line_buffer input = LINE_BUFFER_INIT;
4141

4242
static struct {
43-
uint32_t action, propLength, textLength, srcRev, type;
43+
uint32_t action, propLength, srcRev, type;
44+
off_t text_length;
4445
struct strbuf src, dst;
4546
uint32_t text_delta, prop_delta;
4647
} node_ctx;
@@ -61,7 +62,7 @@ static void reset_node_ctx(char *fname)
6162
node_ctx.type = 0;
6263
node_ctx.action = NODEACT_UNKNOWN;
6364
node_ctx.propLength = LENGTH_UNKNOWN;
64-
node_ctx.textLength = LENGTH_UNKNOWN;
65+
node_ctx.text_length = -1;
6566
strbuf_reset(&node_ctx.src);
6667
node_ctx.srcRev = 0;
6768
strbuf_reset(&node_ctx.dst);
@@ -209,7 +210,7 @@ static void handle_node(void)
209210
{
210211
const uint32_t type = node_ctx.type;
211212
const int have_props = node_ctx.propLength != LENGTH_UNKNOWN;
212-
const int have_text = node_ctx.textLength != LENGTH_UNKNOWN;
213+
const int have_text = node_ctx.text_length != -1;
213214
/*
214215
* Old text for this node:
215216
* NULL - directory or bug
@@ -291,12 +292,12 @@ static void handle_node(void)
291292
}
292293
if (!node_ctx.text_delta) {
293294
fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
294-
fast_export_data(node_ctx.type, node_ctx.textLength, &input);
295+
fast_export_data(node_ctx.type, node_ctx.text_length, &input);
295296
return;
296297
}
297298
fast_export_modify(node_ctx.dst.buf, node_ctx.type, "inline");
298299
fast_export_blob_delta(node_ctx.type, old_mode, old_data,
299-
node_ctx.textLength, &input);
300+
node_ctx.text_length, &input);
300301
}
301302

302303
static void begin_revision(void)
@@ -409,7 +410,15 @@ void svndump_read(const char *url)
409410
break;
410411
case sizeof("Text-content-length"):
411412
if (!constcmp(t, "Text-content-length")) {
412-
node_ctx.textLength = atoi(val);
413+
char *end;
414+
uintmax_t textlen;
415+
416+
textlen = strtoumax(val, &end, 10);
417+
if (!isdigit(*val) || *end)
418+
die("invalid dump: non-numeric length %s", val);
419+
if (textlen > maximum_signed_value_of_type(off_t))
420+
die("unrepresentable length in dump: %s", val);
421+
node_ctx.text_length = (off_t) textlen;
413422
break;
414423
}
415424
if (constcmp(t, "Prop-content-length"))

0 commit comments

Comments
 (0)