fix buffer handling in GraphicsMagick image reading code (solves #10051)