@matheusbsbs / matheus-bagliano / commits / bcd254621f
Fork 0

vcs-svn: read the preimage when applying deltas

The source view offset heading each svndiff0 window represents a number of bytes past the beginning of the preimage. Together with the source view length, it dictates to the delta applier what portion of the preimage instructions will refer to. Read that portion right away using the sliding window code. Maybe some day we will use mmap to read data more lazily. Subversion's implementation tolerates source view offsets pointing past the end of the preimage file but we do not, for simplicity. This does not teach the delta applier to read instructions or copy data from the source view. Deltas that could produce nonempty output will still be rejected. Improved-by: Ramkumar Ramachandra <artagnon@gmail.com> Improved-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Acked-by: Ramkumar Ramachandra <artagnon@gmail.com>

Jonathan Nieder committed Oct 13, 2010 at 04:30 UTC bcd254621f9a98794cdc32906db10af7135824c4
2 files changed +37
t/t9011-svn-da.sh
+35
@@ -86,4 +86,39 @@ test_expect_success 'nonempty (but unused) preimage view' '
86 test_cmp empty actual
87 '
88
89 +test_expect_success 'preimage view: right endpoint cannot backtrack' '
90 + printf "SVNQ%b%b" "Q\003QQQ" "Q\002QQQ" |
91 + q_to_nul >clear.backtrack &&
92 + test_must_fail test-svn-fe -d preimage clear.backtrack 14
93 +'
94 +
95 +test_expect_success 'preimage view: left endpoint can advance' '
96 + printf "SVNQ%b%b" "Q\003QQQ" "\001\002QQQ" |
97 + q_to_nul >clear.preshrink &&
98 + printf "SVNQ%b%b" "Q\003QQQ" "\001\001QQQ" |
99 + q_to_nul >clear.shrinkbacktrack &&
100 + test-svn-fe -d preimage clear.preshrink 14 >actual &&
101 + test_must_fail test-svn-fe -d preimage clear.shrinkbacktrack 14 &&
102 + test_cmp empty actual
103 +'
104 +
105 +test_expect_success 'preimage view: offsets compared by value' '
106 + printf "SVNQ%b%b" "\001\001QQQ" "\0200Q\003QQQ" |
107 + q_to_nul >clear.noisybacktrack &&
108 + printf "SVNQ%b%b" "\001\001QQQ" "\0200\001\002QQQ" |
109 + q_to_nul >clear.noisyadvance &&
110 + test_must_fail test-svn-fe -d preimage clear.noisybacktrack 15 &&
111 + test-svn-fe -d preimage clear.noisyadvance 15 &&
112 + test_cmp empty actual
113 +'
114 +
115 +test_expect_success 'preimage view: reject truncated preimage' '
116 + printf "SVNQ%b" "\010QQQQ" | q_to_nul >clear.lateemptyread &&
117 + printf "SVNQ%b" "\010\001QQQ" | q_to_nul >clear.latenonemptyread &&
118 + printf "SVNQ%b" "\001\010QQQ" | q_to_nul >clear.longread &&
119 + test_must_fail test-svn-fe -d preimage clear.lateemptyread 9 &&
120 + test_must_fail test-svn-fe -d preimage clear.latenonemptyread 9 &&
121 + test_must_fail test-svn-fe -d preimage clear.longread 9
122 +'
123 +
124 test_done
vcs-svn/svndiff.c
+2
@@ -4,6 +4,7 @@
4 */
5
6 #include "git-compat-util.h"
7 +#include "sliding_window.h"
8 #include "line_buffer.h"
9 #include "svndiff.h"
10
@@ -127,6 +128,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
128
129 if (read_offset(delta, &pre_off, &delta_len) ||
130 read_length(delta, &pre_len, &delta_len) ||
131 + move_window(preimage, pre_off, pre_len) ||
132 apply_one_window(delta, &delta_len))
133 return -1;
134 }