summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-main.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-main.h')
-rw-r--r--xdelta3/xdelta3-main.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index ae6fc19..46b2cfb 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -1265,7 +1265,7 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1265 { 1265 {
1266 if (stream->dec_current1.addr >= stream->dec_cpylen) 1266 if (stream->dec_current1.addr >= stream->dec_cpylen)
1267 { 1267 {
1268 VC(UT " T@%-6"Q"u", 1268 VC(UT " T@%-6u",
1269 stream->dec_current1.addr - stream->dec_cpylen)VE; 1269 stream->dec_current1.addr - stream->dec_cpylen)VE;
1270 } 1270 }
1271 else 1271 else
@@ -1293,7 +1293,7 @@ main_print_window (xd3_stream* stream, main_file *xfile)
1293 { 1293 {
1294 if (stream->dec_current2.addr >= stream->dec_cpylen) 1294 if (stream->dec_current2.addr >= stream->dec_cpylen)
1295 { 1295 {
1296 VC(UT " T@%-6"Q"u", 1296 VC(UT " T@%-6u",
1297 stream->dec_current2.addr - stream->dec_cpylen)VE; 1297 stream->dec_current2.addr - stream->dec_cpylen)VE;
1298 } 1298 }
1299 else 1299 else
@@ -1794,6 +1794,7 @@ main_merge_output (xd3_stream *stream, main_file *ofile)
1794 usize_t inst_pos = 0; 1794 usize_t inst_pos = 0;
1795 xoff_t output_pos = 0; 1795 xoff_t output_pos = 0;
1796 xd3_source recode_source; 1796 xd3_source recode_source;
1797 usize_t window_num = 0;
1797 int at_least_once = 0; 1798 int at_least_once = 0;
1798 1799
1799 /* merge_stream is set if there were arguments. this stream's input 1800 /* merge_stream is set if there were arguments. this stream's input
@@ -1821,6 +1822,7 @@ main_merge_output (xd3_stream *stream, main_file *ofile)
1821 xoff_t window_srcmin = 0; 1822 xoff_t window_srcmin = 0;
1822 xoff_t window_srcmax = 0; 1823 xoff_t window_srcmax = 0;
1823 usize_t window_pos = 0; 1824 usize_t window_pos = 0;
1825 usize_t window_size;
1824 1826
1825 /* at_least_once ensures that we encode at least one window, 1827 /* at_least_once ensures that we encode at least one window,
1826 * which handles the 0-byte case. */ 1828 * which handles the 0-byte case. */
@@ -1834,25 +1836,31 @@ main_merge_output (xd3_stream *stream, main_file *ofile)
1834 return XD3_INVALID; 1836 return XD3_INVALID;
1835 } 1837 }
1836 1838
1837 if (main_bsize < stream->dec_tgtlen) 1839 /* Window sizes must match from the input to the output, so that
1840 * target copies are in-range (and so that checksums carry
1841 * over). */
1842 XD3_ASSERT (window_num < stream->whole_target.winsizeslen);
1843 window_size = stream->whole_target.winsizes[window_num++];
1844
1845 if (main_bsize < window_size)
1838 { 1846 {
1839 main_free (main_bdata); 1847 main_free (main_bdata);
1840 main_bdata = NULL; 1848 main_bdata = NULL;
1841 main_bsize = 0; 1849 main_bsize = 0;
1842 if ((main_bdata = (uint8_t*) 1850 if ((main_bdata = (uint8_t*)
1843 main_malloc (stream->dec_tgtlen)) == NULL) 1851 main_malloc (window_size)) == NULL)
1844 { 1852 {
1845 return ENOMEM; 1853 return ENOMEM;
1846 } 1854 }
1847 main_bsize = stream->dec_tgtlen; 1855 main_bsize = window_size;
1848 } 1856 }
1849 1857
1850 /* This encodes a single target window. */ 1858 /* This encodes a single target window. */
1851 while (window_pos < stream->dec_tgtlen && 1859 while (window_pos < window_size &&
1852 inst_pos < stream->whole_target.instlen) 1860 inst_pos < stream->whole_target.instlen)
1853 { 1861 {
1854 xd3_winst *inst = &stream->whole_target.inst[inst_pos]; 1862 xd3_winst *inst = &stream->whole_target.inst[inst_pos];
1855 usize_t take = min(inst->size, stream->dec_tgtlen - window_pos); 1863 usize_t take = min(inst->size, window_size - window_pos);
1856 xoff_t addr; 1864 xoff_t addr;
1857 1865
1858 switch (inst->type) 1866 switch (inst->type)