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 authored and kelson42 committed Jun 22, 2024
1 parent 4819982 commit 14fdd56
Show file tree
Hide file tree
Showing 3 changed files with 22 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
16 changes: 16 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,21 @@ class Grouping
return true;
}

bool FileImpl::checkClusters() {
const cluster_index_type clusterCount = getCountClusters().v;
for ( cluster_index_type i = 0; i < clusterCount; ++i )
{
// Force a read of each clusters (which will throw ZimFileFormatError in case of error)
try {
readCluster(cluster_index_t(i));
} catch (ZimFileFormatError& e) {
std::cerr << e.what() << std::endl;
return false;
}
}
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 14fdd56

Please sign in to comment.