Some years ago when there was a required stopover in SP on flights from NY to Rio, immigration and customs were done in Rio. I don't know how it is currently, but if you are flying on a single ticket, then TAM will put on on the next plane to Rio, no worries. ^