Fix patch bug for zero-length copies and improve bad copy_cb() handling. by dbaarda · Pull Request #206 · librsync/librsync

@dbaarda

Fix a bug which would make librsync patch hang for a corrupt delta containing
a zero-length copy command. Patch will now fail returning RS_CORRUPT on
encountering a zero length copy command.

Make rs_patch_s_copying() do assert() that copy_cb() didn't copy more data
than requested so that debug builds highlight this API violation. Keep the
backwards-compatible defensive behaviour of only copying the amount requested
for non-debug builds, but upgrade the (possibly disabled) trace about it to
log warning. Fix the rs_trace() of "copy callback returned ..." to only output
this trace if the copy_cb() failed.

Tidy rs_patch_s_literal() and rs_patch_s_copy() code for updating stats to
make them consistent.