Avoid decoding the last row which contains corrupt data and causes the image to become black. Closes #5654.