Exception: PNGlitch::DataSizeError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/pnglitch/errors.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, over, expected) ⇒ DataSizeError

Returns a new instance of DataSizeError.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pnglitch/errors.rb', line 4

def initialize filename, over, expected
  over_size = digit_format over
  expected_size = digit_format expected
  message = <<-EOL.gsub(/^\s*/, '')
    The size of your data goes over #{over_size}.
    It should be #{expected_size} actually when it's a normal 
    formatted PNG file.
    PNGlitch raised this error to avoid the attack known as
    "zip bomb". If you are sure that the PNG image is safe, 
    please set manually your own upper size limit as the variable
    of PNGlitch#open.
  EOL
  message = ["\e[31m", message, "\e[0m"].join if STDOUT.tty?  # color red
  message = [
    'Size of the decompressed data is too large - ', 
    filename, "\n\n", message, "\n"
  ].join
  super message
end