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 22, 2024
1 parent 89d8422 commit 4f64d26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## 1.10.4

### 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 @@ -5,7 +5,6 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand All @@ -17,6 +16,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 +407,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 4f64d26

Please sign in to comment.