module ZSteg::Checker::Zlib

Constants

MIN_UNPACKED_SIZE

Public Class Methods

check_data(data) click to toggle source

try to find zlib blog.w3challs.com/index.php?post/2012/03/25/NDH2k12-Prequals-We-are-looking-for-a-real-hacker-Wallpaper-image

# File lib/zsteg/checker/zlib.rb, line 23
def self.check_data data
  return unless idx = data.index(/\x78[\x9c\xda\x01]/n)

  zi = ::Zlib::Inflate.new
  x = zi.inflate data[idx..-1]
  # decompress OK
  return Result.new x, idx if x.size >= MIN_UNPACKED_SIZE
rescue ::Zlib::BufError
  # tried to decompress, but got EOF - need more data
  return Result.new x, idx
rescue ::Zlib::DataError, ::Zlib::NeedDict
  # not a zlib
ensure
  zi.close if zi && !zi.closed?
end