Porosity does not mean that there is oil or gas in the the rocks. In fact the pores could be filled with water. Not only must the rocks have pores, the pores must be connected so that the oil and gas can move through the rock. Scientists measure the ability of oil and gas to move through rock by determining its permeablity . Oil and gas in low permeability rock have difficulty moving out of the rock and into a well.
Permeability is measured in thousandths of a darcy or millidarcys .
Sandstone and carbonate rocks are generally the most porous and permeable rocks and are therefore where scientists usually find oil and gas. The oil and gas formed millions of years ago did not stay in the same place. The permeability of the rocks allowed oil and gas to move through the rocks until they reached a layer of rock that had low permeability. This is like having a sponge filled with water. Water can be added to the sponge and will drip out of it.