fix OOM error on large image files