You lucky person, you have wandered into the minefield which is engendered by the use of the term intellectual property to treat three different areas of law - copyright, trademark, and patent law - as if they were all one big thing (and a thing analogous to real estate law, to boot). RMS writes about this at more length elsewhere, but what this comes down to is that copyrights, patents, and trademarks are three different things.
A piece of software can embody all three at once. Even if you have a copyright licence to use such a piece of software, that licence may say nothing about the patent and/or trademarks therein. If you don't have a licence to use the patent implementation and/or trademarks in a way that would otherwise be infringing, then even though you're not infringing the author's copyright, you still may not use the software.
More recent free software licences, especially those written since it became clear that software patents were a problem, often mention patents, and function as both copyright and patent licences. GPLv3 s11 says that
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
and similarly Apache v2 s3 says that
Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work ...
The problem with GPLv2 is that it was written some time ago, and its mention of patents is limited to preventing them from being used as a shield against a GPL infringment claim by someone who refuses to honour the source-distribution requirements of GPLv2 on the grounds that it would infringe one of their patents.
With respect to your particular case, libheif says it "is distributed under the terms of the GNU Lesser General Public License". It doesn't says which version, which is unhelpful, as LGPLv3 is a set of deltas to GPLv3, and doesn't remove the patent grant therein. So LGPLv3, as I read it, includes the necessary patent grant language, while LGPLv2.1 doesn't. This, however, is not helpful if the author of libheif doesn't hold any of the patents in question.
In answer to your specific questions:
Copyrights and patents are orthogonal. Open-source, aka free, software, is au fond a copyright issue; some free licences, as we have seen, include patent grants; others don't. Knowing that your software is free doesn't tell you whether you have a patent grant; you will have to read the licence to find out.
If the free software you're using infringes some third-party patent, you may not lawfully use it. The patent holder might permit you to purchase a license to use the patent as embodied by the software, but they also might not; it's up to them.