@@ -42,6 +42,26 @@ let trailerLen = 2 * blocksize
4242 #expect( octal11 ( input) == expected)
4343 }
4444
45+ // We should never add a full block (512 bytes) of padding
46+ @Test ( arguments: [
47+ ( input: 0 , expected: 0 ) ,
48+ ( input: 1 , expected: 511 ) ,
49+ ( input: 2 , expected: 510 ) ,
50+ ( input: 511 , expected: 1 ) ,
51+ ( input: 512 , expected: 0 ) ,
52+ ( input: 513 , expected: 511 ) ,
53+ ] )
54+ func testPadded( input: Int , expected: Int ) async throws {
55+ #expect( padding ( input) == expected)
56+ }
57+
58+ @Test ( arguments: 0 ... 1025 )
59+ func testPaddedProperties( input: Int ) async throws {
60+ let output = padding ( input)
61+ #expect( ( input + output) % 512 == 0 ) // The padded output should be a whole number of blocks
62+ #expect( output < 512 ) // we should never write a full block of padding, because tar considers this to be the end of the file
63+ }
64+
4565 @Test func testUInt8writeString( ) async throws {
4666 // Fill the buffer with 0xFF to show null termination
4767 var hdr = [ UInt8] ( repeating: 255 , count: 21 )
0 commit comments