diff options
| author | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-23 17:16:51 +0300 |
|---|---|---|
| committer | Yuriy Andamasov <yuriy@vyos.io> | 2026-05-23 17:16:51 +0300 |
| commit | e5fbde8bb9b21d264f71f25881b44db1af3d03c6 (patch) | |
| tree | 05201cac56a6d3b9c07e7c6644f74d0d86be7801 /src/engine/VyOSElasticModernFulltextStorageEngine.php | |
| parent | 011eec12f9176a6a8b8d8b9133bc00107a7855c0 (diff) | |
| download | phorge-elasticsearch-modern-e5fbde8bb9b21d264f71f25881b44db1af3d03c6.tar.gz phorge-elasticsearch-modern-e5fbde8bb9b21d264f71f25881b44db1af3d03c6.zip | |
Engine: fix negative pagination bounds and _ts accumulation
Two correctness bugs surfaced by CR / Phase 0, both inherited from
the bundled PhabricatorElasticFulltextStorageEngine pattern:
1. executeSearch() did not validate that $offset / $limit were
non-negative. PHP's (int) cast on a negative string yields a
negative int, which would be passed unchecked to Elasticsearch.
Add an explicit non-negative check before the existing upper-
bound (offset + limit > 10000) check.
2. reindexAbstractDocument()'s relationship-data loop assigned the
'_ts' field unconditionally instead of accumulating. For multi-
valued relationships (multiple authorPHID, projectPHID, etc.
entries on the same doc), only the last timestamp survived.
Change to array-append, parallel to the PHID array.
Both fixes diverge from the bundled engine; bundled retains the
faithful-but-broken behavior. Worth fixing in this extension since
we control the wire format.
🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src/engine/VyOSElasticModernFulltextStorageEngine.php')
| -rw-r--r-- | src/engine/VyOSElasticModernFulltextStorageEngine.php | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php index 5c3d9a2..ef4a14d 100644 --- a/src/engine/VyOSElasticModernFulltextStorageEngine.php +++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php @@ -227,7 +227,11 @@ class VyOSElasticModernFulltextStorageEngine $spec[$field_name][] = $related_phid; } if ($time !== null) { - $spec[$field_name.'_ts'] = $time; + if (!isset($spec[$field_name.'_ts'])) { + $spec[$field_name.'_ts'] = array($time); + } else { + $spec[$field_name.'_ts'][] = $time; + } } } @@ -420,6 +424,11 @@ class VyOSElasticModernFulltextStorageEngine $offset = (int)$query->getParameter('offset', 0); $limit = (int)$query->getParameter('limit', 101); + if ($offset < 0 || $limit < 0) { + throw new Exception(pht( + 'Query offset and limit must be non-negative. offset=%d limit=%d', + $offset, $limit)); + } if ($offset + $limit > 10000) { throw new Exception(pht( 'Query offset is too large. offset+limit=%s (max=%s)', |
