From c362b118eaeffa62b273b56d10715ab61f49fd9d Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Mon, 7 Dec 2015 23:50:05 -0800 Subject: One more XD3_TOOFARBACK case handled (regtest.go) --- xdelta3/xdelta3-decode.h | 6 ++++-- xdelta3/xdelta3-main.h | 7 +++++++ xdelta3/xdelta3.c | 34 +++++++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h index 3266425..65877a4 100644 --- a/xdelta3/xdelta3-decode.h +++ b/xdelta3/xdelta3-decode.h @@ -207,6 +207,8 @@ xd3_decode_section (xd3_stream *stream, /* No allocation/copy needed */ section->buf = stream->next_in; sect_take = section->size; + IF_DEBUG1 (DP(RINT "[xd3_decode_section] zerocopy %u @ %u avail %u\n", + sect_take, section->pos, stream->avail_in)); } else { @@ -230,8 +232,8 @@ xd3_decode_section (xd3_stream *stream, section->buf = section->copied1; } - IF_DEBUG2 (DP(RINT "[xd3_decode_section] take %u @ %u[%u] size %u\n", - sect_take, section->pos, section->alloc1, section->size)); + IF_DEBUG2 (DP(RINT "[xd3_decode_section] take %u @ %u [need %u] avail %u\n", + sect_take, section->pos, sect_need, stream->avail_in)); XD3_ASSERT (section->pos + sect_take <= section->alloc1); memcpy (section->copied1 + section->pos, diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h index e7ce493..ede5e73 100644 --- a/xdelta3/xdelta3-main.h +++ b/xdelta3/xdelta3-main.h @@ -856,6 +856,8 @@ main_file_open (main_file *xfile, const char* name, int mode) return XD3_INVALID; } + IF_DEBUG1(DP(RINT "[main] open source %s\n", name)); + #if XD3_STDIO xfile->file = fopen (name, XOPEN_STDIO); @@ -1027,6 +1029,7 @@ main_file_read (main_file *ifile, const char *msg) { int ret = 0; + IF_DEBUG1(DP(RINT "[main] read %s up to %"Z"u\n", ifile->filename, size)); #if XD3_STDIO size_t result; @@ -1067,6 +1070,8 @@ main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) { int ret = 0; + IF_DEBUG1(DP(RINT "[main] write %u\n bytes", size)); + #if XD3_STDIO usize_t result; @@ -1136,6 +1141,8 @@ main_write_output (xd3_stream* stream, main_file *ofile) { int ret; + IF_DEBUG1(DP(RINT "[main] write(%s) %u\n bytes", ofile->filename, stream->avail_out)); + if (option_no_output) { return 0; diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 8dc43e0..0bf2d77 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c @@ -1927,7 +1927,7 @@ xd3_getblk (xd3_stream *stream, xoff_t blkno) ret = stream->getblk (stream, source, blkno); if (ret != 0) { - IF_DEBUG1 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", + IF_DEBUG2 (DP(RINT "[getblk] app error blkno %"Q"u: %s\n", blkno, xd3_strerror (ret))); return ret; } @@ -3750,13 +3750,17 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos) if (srcpos < stream->srcwin_cksum_pos && stream->srcwin_cksum_pos - srcpos > src->max_winsize) { - IF_DEBUG1(DP(RINT "[match_setup] rejected due to src->max_winsize " + IF_DEBUG2(DP(RINT "[match_setup] rejected due to src->max_winsize " "distance eof=%"Q"u srcpos=%"Q"u max_winsz=%"Q"u\n", xd3_source_eof (src), srcpos, src->max_winsize)); goto bad; } + /* There are cases where the above test does not reject a match that + * will experience XD3_TOOFARBACK at the first xd3_getblk call + * because the input may have advanced up to one block beyond the + * actual EOF. */ IF_DEBUG2(DP(RINT "[match_setup] %"Q"u srcpos %"Q"u, " "src->max_winsize %"Q"u\n", stream->total_in + stream->input_position, @@ -3929,9 +3933,6 @@ xd3_source_extend_match (xd3_stream *stream) usize_t tryrem; /* tryrem is the number of matchable bytes */ usize_t matched; - IF_DEBUG2(DP(RINT "[extend match] srcpos %"Q"u\n", - stream->match_srcpos)); - XD3_ASSERT (src != NULL); /* Does it make sense to compute backward match AFTER forward match? */ @@ -3957,8 +3958,10 @@ xd3_source_extend_match (xd3_stream *stream) { if (ret == XD3_TOOFARBACK) { - IF_DEBUG1(DP(RINT "[maxback] %"Q"u TOOFARBACK: %u\n", - tryblk, stream->match_back)); + IF_DEBUG2(DP(RINT "[maxback] %"Q"u TOOFARBACK: %u INP %"Q"u CKSUM %"Q"u\n", + tryblk, stream->match_back, + stream->total_in + stream->input_position, + stream->srcwin_cksum_pos)); /* the starting position is too far back. */ if (stream->match_back == 0) @@ -4014,7 +4017,14 @@ xd3_source_extend_match (xd3_stream *stream) if ((ret = xd3_getblk (stream, tryblk))) { - XD3_ASSERT (ret != XD3_TOOFARBACK); + if (ret == XD3_TOOFARBACK) + { + IF_DEBUG2(DP(RINT "[maxfwd] %"Q"u TOOFARBACK: %u INP %"Q"u CKSUM %"Q"u\n", + tryblk, stream->match_fwd, + stream->total_in + stream->input_position, + stream->srcwin_cksum_pos)); + goto donefwd; + } /* could be a XD3_GETSRCBLK failure. */ return ret; @@ -4048,6 +4058,11 @@ xd3_source_extend_match (xd3_stream *stream) donefwd: stream->match_state = MATCH_SEARCHING; + IF_DEBUG2(DP(RINT "[extend match] input %"Q"u srcpos %"Q"u len %u\n", + stream->input_position + stream->total_in, + stream->match_srcpos, + stream->match_fwd)); + /* If the match ends short of the last instruction end, we probably * don't want it. There is the possibility that a copy ends short * of the last copy but also goes further back, in which case we @@ -4099,8 +4114,9 @@ xd3_source_extend_match (xd3_stream *stream) IF_DEBUG2 ({ static int x = 0; - DP(RINT "[source match:%d] (%s) [ %u bytes ]\n", + DP(RINT "[source match:%d] length %u (%s) [ %u bytes ]\n", x++, + match_length, stream->total_in + target_position, stream->total_in + target_position + match_length, match_position, -- cgit v1.2.3