Sha256: fb865e1dac09b3d02333a2540e062b4e897b233f2dbcaedab67ae0c735bcddef

Contents?: true

Size: 1.8 KB

Versions: 170

Compression:

Stored size: 1.8 KB

Contents

class Puppet::ModuleTool::Tar::Mini
  def unpack(sourcefile, destdir, _)
    Zlib::GzipReader.open(sourcefile) do |reader|
      Archive::Tar::Minitar.unpack(reader, destdir, find_valid_files(reader)) do |action, name, stats|
        case action
        when :file_done
          File.chmod(0644, "#{destdir}/#{name}")
        when :dir, :file_start
          validate_entry(destdir, name)
          Puppet.debug("Extracting: #{destdir}/#{name}")
        end
      end
    end
  end

  def pack(sourcedir, destfile)
    Zlib::GzipWriter.open(destfile) do |writer|
      Archive::Tar::Minitar.pack(sourcedir, writer)
    end
  end

  private

  # Find all the valid files in tarfile.
  #
  # This check was mainly added to ignore 'x' and 'g' flags from the PAX
  # standard but will also ignore any other non-standard tar flags.
  # tar format info: https://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Ftaf.htm
  # pax format info: https://pic.dhe.ibm.com/infocenter/zos/v1r13/index.jsp?topic=%2Fcom.ibm.zos.r13.bpxa500%2Fpxarchfm.htm
  def find_valid_files(tarfile)
    Archive::Tar::Minitar.open(tarfile).collect do |entry|
      flag = entry.typeflag
      if flag.nil? || flag =~ /[[:digit:]]/ && (0..7).include?(flag.to_i)
        entry.full_name
      else
        Puppet.debug "Invalid tar flag '#{flag}' will not be extracted: #{entry.name}"
        next
      end
    end
  end

  def validate_entry(destdir, path)
    if Pathname.new(path).absolute?
      raise Puppet::ModuleTool::Errors::InvalidPathInPackageError, :entry_path => path, :directory => destdir
    end

    path = File.expand_path File.join(destdir, path)

    if path !~ /\A#{Regexp.escape destdir}/
      raise Puppet::ModuleTool::Errors::InvalidPathInPackageError, :entry_path => path, :directory => destdir
    end
  end
end

Version data entries

170 entries across 170 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/module_tool/tar/mini.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/module_tool/tar/mini.rb
bolt-0.17.1 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.17.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.16.4 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.16.3 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.16.2 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.16.1 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.16.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.15.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.14.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.13.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/module_tool/tar/mini.rb
bolt-0.12.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.11.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.10.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/module_tool/tar/mini.rb
bolt-0.9.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
bolt-0.8.0 vendored/puppet/lib/puppet/module_tool/tar/mini.rb
puppet-4.10.9 lib/puppet/module_tool/tar/mini.rb