Skip to content

Commit

Permalink
Add a check kind to check clusters' content.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Jun 10, 2024
1 parent 643b023 commit a5d1c2f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/zim/zim.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ namespace zim
*/
CLUSTER_PTRS,

/**
* Checks that offsets inside each clusters are valid.
*/
CLUSTERS_OFFSETS,

/**
* Checks that mime-type values in dirents are valid.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/fileimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ class Grouping
case IntegrityCheck::DIRENT_ORDER: return FileImpl::checkDirentOrder();
case IntegrityCheck::TITLE_INDEX: return FileImpl::checkTitleIndex();
case IntegrityCheck::CLUSTER_PTRS: return FileImpl::checkClusterPtrs();
case IntegrityCheck::CLUSTERS_OFFSETS: return FileImpl::checkClusters();
case IntegrityCheck::DIRENT_MIMETYPES: return FileImpl::checkDirentMimeTypes();
case IntegrityCheck::COUNT: ASSERT("shouldn't have reached here", ==, "");
}
Expand Down Expand Up @@ -676,6 +677,16 @@ class Grouping
return true;
}

bool FileImpl::checkClusters() {
const cluster_index_type clusterCount = getCountClusters().v;
for ( cluster_index_type i = 0; i < clusterCount; ++i )
{
// For a read of each clusters (which will throw ZimFileFormatError in case of error)
readCluster(cluster_index_t(i));
}
return true;
}

bool FileImpl::checkClusterPtrs() {
const cluster_index_type clusterCount = getCountClusters().v;
const offset_t validClusterRangeStart(80); // XXX: really???
Expand Down
1 change: 1 addition & 0 deletions src/fileimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace zim
bool checkDirentOrder();
bool checkTitleIndex();
bool checkClusterPtrs();
bool checkClusters();
bool checkDirentMimeTypes();
};

Expand Down

0 comments on commit a5d1c2f

Please sign in to comment.