Williams rallied past Caroline Wozniacki 1-6, 6-3, 6-2 while Sharapova advanced without having to take the court.
Sharapova had been scheduled to face Lucie Safarova in the third round, but Safarova withdrew due to illness.
It will be the 10th career meeting for Sharapova and Williams, with Williams holding a 7-2 advantage. Both of Sharapova's wins came in 2004 with one of them taking place in the final at Wimbledon.
In other matches Thursday, Agnieszka Radwanska defeated Roberta Vinci 7-6 (7-1), 6-4 and Lucie Hradecka eliminated Ekaterina Makarova 6-2, 7-6 (7-5). Hradecka's victory followed her surprising win Wednesday over current Wimbledon champion Petra Kvitova.
Benedict Cumberbatch's dramatic reading of R. Kelly lyrics is just what you need
Exploding whale video goes viral on Internet