Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_tar_magic to properly return an array when a file has less than 264 characters #30

Merged
merged 2 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mixlib/archive/tar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/mixlib/tar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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