From 8c7d3368daa517312604993d90f341e94736aff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= Date: Tue, 13 Jan 2026 02:15:22 +0100 Subject: [PATCH] Fix reading of last page in ogg stream When trying to read a packet from the last page the readPages() method would return false for all packets on the last page. Move the lastPage check just before trying to create the next page, and after the packetIndex check of the last fetched page. --- taglib/ogg/oggfile.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index 29f1803a..c08ffde8 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -191,13 +191,16 @@ bool Ogg::File::readPages(unsigned int i) const Page *page = d->pages.back(); packetIndex = nextPacketIndex(page); offset = page->fileOffset() + page->size(); + + // Enough pages have been fetched. + if(packetIndex > i) { + return true; + } + else if(page->header()->lastPageOfStream()) { + return false; + } } - // Enough pages have been fetched. - - if(packetIndex > i) - return true; - // Read the next page and add it to the page list. auto nextPage = new Page(this, offset); @@ -208,9 +211,6 @@ bool Ogg::File::readPages(unsigned int i) nextPage->setFirstPacketIndex(packetIndex); d->pages.append(nextPage); - - if(nextPage->header()->lastPageOfStream()) - return false; } }