Rio is neither dirty nor filled with rampant crime. Rio is one of the world's most civilized and cosmopolitan cities.
In actual fact, Rio is far cleaner than almost any city in the United States or Europe, and is amongst the most well maintained cities anywhere. Rio is kept scrupulously clean -- as clean as any city of 10 million people can be --by a very efficient sanitation department, which does an excellent job keeping the streets and beaches pristine. Although it hovers around 100 Degrees F all summer, one rarely encounters unpleasant smells, the sort of which are commonplace in large North American or European cities. Cariocas -- and Brazilians generally -- are fastidious about hygiene, and given your misconceptions, you will no doubt be pleasantly surprised at how clean Rio is.
The crime issue is a legitimate concern, but Rio is not at all filled with rampant crime. Although the illegal drug trade has created a lot of violent crime in the favelas -- which are now being brought back into police control -- the south of Rio where most tourists will spend their time has a crime rate that is more or less comparable to many large North American cities. One should use the same level of vigilance as would have been appropriate in pre-Guiliani era New York -- don't flash cash or valuables, don't walk in dark unpopulated areas at night, etc. -- and you will be fine.