That's definitely not the case. Some licenses like Apache-2 explicitly grant you the use of necessary patents. Others do not. And there are projects which are absolutely covered by patents, yet the code is opensource. That was the situation with Gif and MP3 formats for years.
I was involved with an opensource project which got a patent application submitted by the company. Even though I pointed out prior art. And even though I refused to sign the application as one of the authors. That's corporate environment for you.