The encrypted file was a multiple of 8192, so $lastChunkNr was set to the chunk AFTER the last chunk.
Then $lastChunkSize is 0 and your code before lead to the warnings described in https://github.com/owncloud/mirall/issues/1009#issuecomment-24731209
By doing ceil()-1 you definitely get to the last chunk..

Then somehow the function returns a wrong size and csync received a "Bad Request" because of https://github.com/owncloud/core/blob/master/lib/private/connector/sabre/aborteduploaddetectionplugin.php#L74