- Clarify misleading logic when the buffer couldn't be allocated. - Use a utility function to calculate the thumbnail size. - Calculate the thumbnail size for the on-disk thumbnail separately (corrects minor rounding error) caused by scaling the smaller size up.