Skip to content

Commit

Permalink
Pipeline instanciation: fix performance issues on huge (broken) strin…
Browse files Browse the repository at this point in the history
…gs which managed somehow to cause nested pipelines not caught due to some non-roundtripability in parsing/serializing. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=37489
  • Loading branch information
rouault committed Aug 26, 2021
1 parent db5a6e6 commit 1cdd004
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,8 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) {
It may even use free formatting "proj = utm; zone =32 ellps= GRS80".
Note that the semicolon separator is allowed, but not required.
**************************************************************************************/
PJ *P;
char *args, **argv;
size_t argc, n;
int ret;
int allow_init_epsg;

if (nullptr==ctx)
ctx = pj_get_default_ctx ();
Expand Down Expand Up @@ -816,19 +813,11 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition) {
return nullptr;
}

/* ...and let pj_init_ctx do the hard work */
/* New interface: forbid init=epsg:XXXX syntax by default */
allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, FALSE);
P = pj_init_ctx_with_allow_init_epsg (ctx, (int) argc, argv, allow_init_epsg);
PJ* P = pj_create_argv_internal (ctx, (int) argc, argv);

free (argv);
free (args);

/* Support cs2cs-style modifiers */
ret = cs2cs_emulation_setup (P);
if (0==ret)
return proj_destroy (P);

return P;
}

Expand Down Expand Up @@ -867,28 +856,25 @@ indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm",
/*************************************************************************************/
PJ *pj_create_argv_internal (PJ_CONTEXT *ctx, int argc, char **argv) {
/**************************************************************************************
Same as proj_create_argv() but calls pj_create_internal() instead of proj_create() internally
For use by pipeline init function.
**************************************************************************************/
PJ *P;
const char *c;

if (nullptr==ctx)
ctx = pj_get_default_ctx ();
if (nullptr==argv) {
proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_MISSING_ARG);
return nullptr;
}

/* We assume that free format is used, and build a full proj_create compatible string */
c = pj_make_args (argc, argv);
if (nullptr==c) {
proj_context_errno_set(ctx, PROJ_ERR_OTHER /*ENOMEM*/);
return nullptr;
}
/* ...and let pj_init_ctx do the hard work */
/* New interface: forbid init=epsg:XXXX syntax by default */
const int allow_init_epsg = proj_context_get_use_proj4_init_rules(ctx, FALSE);
PJ* P = pj_init_ctx_with_allow_init_epsg (ctx, argc, argv, allow_init_epsg);

P = pj_create_internal (ctx, c);
/* Support cs2cs-style modifiers */
int ret = cs2cs_emulation_setup (P);
if (0==ret)
return proj_destroy (P);

free ((char *) c);
return P;
}

Expand Down

0 comments on commit 1cdd004

Please sign in to comment.