From f7b7755743d385b8e63c384ccf2a168362a14720 Mon Sep 17 00:00:00 2001 From: Brian Dwyer Date: Mon, 27 Aug 2018 22:34:04 -0400 Subject: [PATCH 1/2] Add a failing test for small files --- spec/mixlib/tar_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/mixlib/tar_spec.rb b/spec/mixlib/tar_spec.rb index f9e7373..3b4f71a 100644 --- a/spec/mixlib/tar_spec.rb +++ b/spec/mixlib/tar_spec.rb @@ -98,6 +98,13 @@ expect(extractor.send(:is_tar_archive?, raw)).to eq(false) end end + context "invalid small file" do + let(:data) { "testdir/#{Array.new(11) { "\x00" }.join}smallfile" } + it "does not identify an invalid header in a small file" do + extractor = described_class.new(tgz_archive) + expect(extractor.send(:is_tar_archive?, raw)).to eq(false) + end + end end end From 8446b32f273b17947d980f3ee7b208e7f68598f8 Mon Sep 17 00:00:00 2001 From: Brian Dwyer Date: Mon, 27 Aug 2018 22:43:30 -0400 Subject: [PATCH 2/2] Always cast as an array to handle files less than 264 chars Signed-off-by: Brian Dwyer --- lib/mixlib/archive/tar.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mixlib/archive/tar.rb b/lib/mixlib/archive/tar.rb index 30c8f9e..dcdb5b9 100644 --- a/lib/mixlib/archive/tar.rb +++ b/lib/mixlib/archive/tar.rb @@ -125,7 +125,7 @@ def is_tar_archive?(io) def read_tar_magic(io) io.rewind - magic = io.read(512).bytes[257..264].pack("C*") + magic = Array(io.read(512).bytes[257..264]).pack("C*") io.rewind magic end