Skip to content

Commit

Permalink
fix crash caused by overly complex filters, fixes #330
Browse files Browse the repository at this point in the history
instead of iterating through the normalized filter, this checks for the presence of non-snapshot compatible filters by recursively searching through the filter tree.
  • Loading branch information
tyrasd committed Aug 9, 2024
1 parent eb42115 commit 3adea1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## unreleased

### Bug Fixes
* Fix crash in non-contribution based endpoints caused by very long and complex filters ([#330])

[#330]: https://github.com/GIScience/ohsome-api/issues/330


## 1.10.3

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.heigit.ohsome.ohsomeapi.utils.TimestampFormatter;
import org.heigit.ohsome.oshdb.OSHDBTag;
import org.heigit.ohsome.oshdb.api.mapreducer.MapReducer;
import org.heigit.ohsome.oshdb.filter.BinaryOperator;
import org.heigit.ohsome.oshdb.filter.ChangesetIdFilterEquals;
import org.heigit.ohsome.oshdb.filter.ChangesetIdFilterEqualsAnyOf;
import org.heigit.ohsome.oshdb.filter.ChangesetIdFilterRange;
Expand Down Expand Up @@ -407,10 +408,16 @@ public FilterExpression parseFilter(FilterParser fp, String filter) {
* see also <a href="https://github.com/GIScience/ohsome-api/issues/289">#289</a>.</p>
*/
public static boolean filterSuitableForSnapshots(FilterExpression filter) {
return filter.normalize().stream().flatMap(Collection::stream)
.noneMatch(f -> f instanceof ChangesetIdFilterEquals
|| f instanceof ChangesetIdFilterRange
|| f instanceof ChangesetIdFilterEqualsAnyOf);
if (filter instanceof ChangesetIdFilterEquals
|| filter instanceof ChangesetIdFilterRange
|| filter instanceof ChangesetIdFilterEqualsAnyOf) {
return false;
}
if (filter instanceof BinaryOperator operator) {
return filterSuitableForSnapshots(operator.getLeftOperand())
&& filterSuitableForSnapshots(operator.getRightOperand());
}
return true;
}

/**
Expand Down

0 comments on commit 3adea1b

Please sign in to comment.