Skip to content

Commit f6d4bdd

Browse files
veloman-yunkankelson42
authored andcommitted
Detection of misaligned value of 1st blob offset in cluster
1 parent 93057c0 commit f6d4bdd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/cluster.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ getClusterReader(const Reader& zimReader, offset_t offset, Cluster::Compression*
108108

109109
size_t n_offset = offset / sizeof(OFFSET_TYPE);
110110

111+
if ( n_offset * sizeof(OFFSET_TYPE) != offset ) {
112+
throw zim::ZimFileFormatError("Error parsing cluster. Offset of the first blob is not properly aligned.");
113+
}
114+
111115
// read offsets
112116
m_blobOffsets.clear();
113117
m_blobOffsets.reserve(n_offset);

test/archive.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,21 @@ TEST_F(ZimArchive, validate)
806806
"Error parsing cluster. Offset of the first blob is too small.\n"
807807
)
808808

809+
TEST_BROKEN_ZIM_NAME(
810+
"invalid.misaligned_offset_of_first_blob_in_cluster_9.zim",
811+
"Error parsing cluster. Offset of the first blob is not properly aligned.\n"
812+
)
813+
814+
TEST_BROKEN_ZIM_NAME(
815+
"invalid.misaligned_offset_of_first_blob_in_cluster_10.zim",
816+
"Error parsing cluster. Offset of the first blob is not properly aligned.\n"
817+
)
818+
819+
TEST_BROKEN_ZIM_NAME(
820+
"invalid.misaligned_offset_of_first_blob_in_cluster_11.zim",
821+
"Error parsing cluster. Offset of the first blob is not properly aligned.\n"
822+
)
823+
809824
TEST_BROKEN_ZIM_NAME(
810825
"invalid.offset_in_cluster.zim",
811826
"Error parsing cluster. Offsets are not ordered.\n"

0 commit comments

Comments
 (0)