Skip to content

Commit

Permalink
Fix for multipart checksums involving file chunks made entirely of li…
Browse files Browse the repository at this point in the history
…ne tabulation (0x0B) elements
  • Loading branch information
elohanlon committed May 8, 2024
1 parent c296c3d commit 9a187ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/atc/utils/aws_checksum_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.multipart_checksum_for_file(file_path, calculate_whole_object: false)
def self.digest_file(file_path, part_size, crc32c_accumulator, whole_object_digester)
File.open(file_path, 'rb') do |file|
buffer = String.new
while file.read(part_size, buffer).present?
while file.read(part_size, buffer) != nil
crc32c_accumulator << Digest::CRC32c.digest(buffer)
whole_object_digester&.update(buffer)
end
Expand Down
32 changes: 32 additions & 0 deletions spec/atc/utils/aws_checksum_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@
expect(described_class.checksum_string_for_file(f.path, multipart_threshold)).to eq('g38HMg==')
end
end

# NOTE: We ran into this issue in the past, so that's why this test exists
it 'properly handles chunks that are made entirely of line tabulation (0x0B) elements' do
Tempfile.create('example-file-to-checksum') do |f|
f.write('A' * 5.megabytes)
f.write(Atc::Utils::HexUtils.hex_to_bin('0B') * 5.megabytes)
f.write(Atc::Utils::HexUtils.hex_to_bin('0B') * 5.megabytes)
f.write('A' * 5.megabytes)
expect(described_class.checksum_string_for_file(f.path, 5.megabytes)).to eq('YjA5PQ==-4')
end
end
end

describe '.digest_file' do
let(:crc32c_accumulator) { [] }
let(:whole_object_digester) { Digest::CRC32c.new }
let(:part_size) { 5.megabytes }

# NOTE: We ran into this issue in the past, so that's why this test exists
it 'properly handles chunks that are made entirely of line tabulation (0x0B) elements' do
Tempfile.create('example-file-to-checksum') do |f|
f.write('A' * part_size)
f.write(Atc::Utils::HexUtils.hex_to_bin('0B') * part_size)
f.write(Atc::Utils::HexUtils.hex_to_bin('0B') * part_size)
f.write('A' * part_size)
described_class.digest_file(f.path, part_size, crc32c_accumulator, whole_object_digester)
end
expect(
crc32c_accumulator.map { |checksum_bin_value| Base64.strict_encode64(checksum_bin_value) }
).to eq(['MDaLrw==', '6TPWQg==', '6TPWQg==', 'MDaLrw=='])
expect(whole_object_digester.base64digest).to eq('vobXrQ==')
end
end

describe '.compute_default_part_size' do
Expand Down

0 comments on commit 9a187ef

Please sign in to comment.