Skip to content

Exception on reading big files #41

@wolfgang371

Description

@wolfgang371

I tried to load a really big .png (32768x32768 or even 65536x65536) which unfortunately crashed.
When stripping the code fragment down I realized that writing seems to work, but reading crashes roundabout at 0x2d60 size.

# https://crystalshards.org/shards/github/stumpycr/stumpy_png

require "stumpy_png"

include StumpyPNG

SIZE = 0x2d60 # 0x2d40 works, 0x2d60 breaks

canvas = Canvas.new(SIZE, SIZE)
StumpyPNG.write(canvas, "foo.png") # still works
canvas = StumpyPNG.read("foo.png") # raises below exception

# triggers:
# Unhandled exception: Arithmetic overflow (OverflowError)
#   from /snap/crystal/1064/share/crystal/src/math/math.cr:738:7 in 'pw2ceil'
#   from /snap/crystal/1064/share/crystal/src/io/memory.cr:96:26 in 'write'
#   from /snap/crystal/1064/share/crystal/src/io.cr:1144:7 in 'copy'
#   from lib/stumpy_png/src/stumpy_png/png.cr:57:9 in 'parse_IEND'
#   from lib/stumpy_png/src/stumpy_png/png.cr:219:20 in 'parse_chunk'
#   from lib/stumpy_png/src/stumpy_png.cr:31:7 in 'read'
#   from lib/stumpy_png/src/stumpy_png.cr:23:7 in 'read'
#   from src/merger.cr:11:1 in '__crystal_main'
#   from /snap/crystal/1064/share/crystal/src/crystal/main.cr:115:5 in 'main_user_code'
#   from /snap/crystal/1064/share/crystal/src/crystal/main.cr:101:7 in 'main'
#   from /snap/crystal/1064/share/crystal/src/crystal/main.cr:127:3 in 'main'
#   from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
#   from /home/wolfgang/snap/crystal/common/.cache/crystal/crystal-run-merger.tmp in '_start'
#   from ???

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions