Skip to content

Commit f4fde53

Browse files
committed
ob_tran.cpp: setup(): fix quadratic performance issue in the number of projection parameters
Does not matter for nominal use cases, but fixes huge processing time on fuzzer generated PROJ strings with huge number of parameters. Fixes https://issues.oss-fuzz.com/issues/499119740
1 parent 3663139 commit f4fde53

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/projections/ob_tran.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#include <errno.h>
33
#include <math.h>
4+
#include <set>
45
#include <stddef.h>
56
#include <string.h>
67

@@ -206,15 +207,18 @@ PJ *PJ_PROJECTION(ob_tran) {
206207
return destructor(P, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
207208
}
208209

210+
// Colect used parameters from the R object
211+
std::set<std::string> setUsedRParams;
212+
for (auto r = R->params; r; r = r->next) {
213+
if (r->used) {
214+
setUsedRParams.insert(r->param);
215+
}
216+
}
217+
209218
// Transfer the used flag from the R object to the P object
210219
for (auto p = P->params; p; p = p->next) {
211-
if (!p->used) {
212-
for (auto r = R->params; r; r = r->next) {
213-
if (r->used && strcmp(r->param, p->param) == 0) {
214-
p->used = 1;
215-
break;
216-
}
217-
}
220+
if (!p->used && setUsedRParams.find(p->param) != setUsedRParams.end()) {
221+
p->used = 1;
218222
}
219223
}
220224

0 commit comments

Comments
 (0)