Fix CreateRepositoryFromSnapshot test for malformed archives
The issue says:
CreateRepositoryFromArchive
RPC does not return errors when passing it an archive of an almost-empty repository that gets truncated. It seems like tar(1) will not return an error when it is being truncated in the header fields or something similar.
I believe problem is the way we are "malforming" the archive in the test. We are just getting the half of the tar file and expect it to be malformed and return error. I did some observations with same file:
Divide By | Error Returned |
---|---|
2 | no |
3 | no |
4 | yes |
5 | yes |
6 | no |
7 | yes |
Tar archives consist of a series of 512-byte blocks. Each file in the archive is preceded by a header block containing metadata, followed by the file's contents (padded to a multiple of 512 bytes if necessary). Therefore my assumption is untar operation succeeds when headers are intact after the division. But when we divide by certain amounts which coincidentally divides at a header, then untar operation fails.
Instead of this, we can directly corrupt a header and make sure that archive is malformed.
Let me know if this test was specifically trying to test the case where archive is truncated rather than corrupting the header.
I have been trying out different stuff on validating the tar content using archive/tar library but couldn't succeed. Verification is either too strict or too lenient.
But while trying to validate the tar, I've realised the output of generateTarFile
is too big. Because my validation code was only reading 10240 bytes while total size was 30720 bytes. Later I tried creating tar file using go library instead of the current command execution, and generated file size is 11264 bytes which looks correct; 10240 + 1024 padding. So I feel like there is something weird with the way we generate tar files in the test.
Closes #5503 (closed)