Better sanity check handling WordITerator, position list decode 2
Better sanity check handling WordITerator, position list decode 2
diff --git a/src/library/index_bundle_iterators/WordIterator.php b/src/library/index_bundle_iterators/WordIterator.php
index 6a9bbb5cb..661e880d8 100644
--- a/src/library/index_bundle_iterators/WordIterator.php
+++ b/src/library/index_bundle_iterators/WordIterator.php
@@ -487,6 +487,7 @@ class WordIterator extends IndexBundleIterator
IndexDocumentBundle::POSITIONS_FILENAME;
$fh = (file_exists($positions_filename)) ?
fopen($positions_filename, "r") : false;
+ $file_size = file_size($positions_filename);
$number_of_partitions = $this->total_number_of_partitions;
$num_doc_keys = $doc_map_tools->countTableEntries($doc_map_filename);
$is_ascending = ($this->direction == self::ASCENDING);
@@ -496,7 +497,8 @@ class WordIterator extends IndexBundleIterator
max($this->total_num_docs, 1);
foreach ($postings as $posting) {
$posting[self::GENERATION] = $partition;
- if ($posting['POSITIONS_LEN'] > 0 && !empty($fh)) {
+ if ($posting['POSITIONS_LEN'] > 0 && $file_size < $posting['POSITIONS_LEN']
+ && !empty($fh)) {
if (fseek($fh, $posting['POSITIONS_OFFSET']) >= 0) {
$encoded_positions = fread($fh, $posting['POSITIONS_LEN']);
$posting[self::POSITION_LIST] = L\decodePositionList(