It is usually difficult to determine the actual safety factors of rock masses in an ordinary two-dimensional stability analysis if the safety factors of the different cross sections in the rock mass vary significantly. In addition to the actual slope, arch dam abutment, and the actual foundation of a high building, another example is that the different cross sections of the foundation in the monolith of a gravity dam vary significantly, just like the condition at the overflow dam in the Baise project. A three-dimensional stability analysis method based on the upper-bound theorem was employed to solve this problem. The parameters used in the analysis were obtained from geomechanics tests, as well as continuity simulations of the randomly distributed joints. Two failure patterns against sliding are analyzed. One pattern is the foundation slide along deep-seated planes which were determined by calculations. The other pattern is the foundation slide along the planes across the bottom of the high steps in the foundation pit. The results indicate that a special overflow dam monolith can be considered to be safe in case of considering the three dimensional effect. However, a key wall with a depth of 5m must be constructed at the upper side of this monolith in order to ensure the safety of the foundation.