Skip to content

Commit 6dd4e28

Browse files
committed
Fix bzip2 handling issue when reading concatenated bzip2 streams such as osm.bz2 files of all changesets with discussions (e.g. discussions-250519.osm.bz2 from planet.osm.org)
1 parent 5ad2bab commit 6dd4e28

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/osmium/io/bzip2_compression.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,18 @@ namespace osmium {
313313
throw bzip2_error{"bzip2 error: read open failed", bzerror};
314314
}
315315
} else {
316-
m_stream_end = true;
316+
// Close current stream and try to open a new one for multi-stream files
317+
::BZ2_bzReadClose(&bzerror, m_bzfile);
318+
if (bzerror != BZ_OK) {
319+
throw bzip2_error{"bzip2 error: read close failed", bzerror};
320+
}
321+
// Try to open a new stream - there might be more bzip2 streams concatenated
322+
m_bzfile = ::BZ2_bzReadOpen(&bzerror, m_file.file(), 0, 0, nullptr, 0);
323+
if (!m_bzfile || bzerror != BZ_OK) {
324+
// If we can't open a new stream, we've truly reached the end
325+
m_stream_end = true;
326+
m_bzfile = nullptr;
327+
}
317328
}
318329
} else {
319330
m_stream_end = true;

0 commit comments

Comments
 (0)