Pupil size is an important parameter since it governs the magnitude of ocular aberrations. The pupil size of a human eye has significant individual differences and varies with light level and accommodation. In order to accurately measure ocular aberrations under different pupil sizes using a Shack-Hartmann wavefront sensor (SHWFS), two types of relationship matrices R (1) and R (2) were proposed, which corresponded to wavefront reconstruction with and without an aperture stop, respectively. The numerical and experimental results indicated that matrix R (2) can significantly improve the accuracy of wavefront restoration when the incident beam size is inconsistent with the wavefront reconstruction aperture. Meanwhile, the impact of the aperture stop on the reconstruction accuracy will become smaller and smaller as the ratio ρ of the outer area to the detection aperture decreases. This study not only can be used for accurately measuring ocular aberrations under different pupil sizes, but also for other variable aperture aberrations measurement in other applications.