Skip to content

Commit af64cc0

Browse files
author
Grok Compression
committed
JP2Grok: make grok native vsicurl support opt in
User must set OPJLIKE_VSICURL_NATIVE=YES to opt in, otherwise GDAL virtual file system is used to read from network.
1 parent be4b7d4 commit af64cc0

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

frmts/grok/grkdatasetbase.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,26 @@ template <size_t N> void safe_strcpy(char (&dest)[N], const std::string &src)
114114
/**
115115
* @brief True if @p filename is a network path handled natively by Grok.
116116
*
117-
* Both /vsis3/ and /vsicurl/ are fetched via libcurl inside Grok; /vsis3/
118-
* needs AWS credentials resolved by GDAL, /vsicurl/ only needs the shared
119-
* HTTP auth options (.netrc, cookies, allow-insecure).
117+
* /vsis3/ is always handed to Grok (AWS credentials are resolved by GDAL
118+
* before the path reaches Grok).
119+
*
120+
* /vsicurl/ is only handed to Grok when the user explicitly opts in by
121+
* setting the OPJLIKE_VSICURL_NATIVE_OPT config option (or open option) to YES.
122+
* Without the flag GDAL reads via curl and streams the bytes to Grok,
123+
* which is the safe default.
120124
*/
121125
static bool isGrokNetworkPath(const char *filename)
122126
{
123-
return STARTS_WITH(filename, "/vsis3/") ||
124-
STARTS_WITH(filename, "/vsicurl/");
127+
if (STARTS_WITH(filename, "/vsis3/"))
128+
return true;
129+
130+
if (STARTS_WITH(filename, "/vsicurl/"))
131+
{
132+
return CPLTestBool(
133+
CPLGetConfigOption(OPJLIKE_VSICURL_NATIVE_OPT, "NO"));
134+
}
135+
136+
return false;
125137
}
126138

127139
/**

frmts/opjlike/jp2opjlikedataset.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,11 @@ GDALDataset *JP2OPJLikeDataset<CODEC, BASE>::Open(GDALOpenInfo *poOpenInfo)
14071407
if (!Identify(poOpenInfo) || poOpenInfo->fpL == nullptr)
14081408
return nullptr;
14091409

1410+
const char *pszNative = CSLFetchNameValueDef(
1411+
poOpenInfo->papszOpenOptions, OPJLIKE_VSICURL_NATIVE_OPT, nullptr);
1412+
if (pszNative)
1413+
CPLSetThreadLocalConfigOption(OPJLIKE_VSICURL_NATIVE_OPT, pszNative);
1414+
14101415
/* Detect which codec to use : J2K or JP2 ? */
14111416
vsi_l_offset nCodeStreamLength = 0;
14121417
vsi_l_offset nCodeStreamStart =

frmts/opjlike/jp2opjlikedataset.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
#include "gdaljp2abstractdataset.h"
2424
#include "gdaljp2metadata.h"
2525

26+
/** Environment variable / open option that must be set to YES to let opjlike
27+
* codec handle /vsicurl/ reads natively.
28+
*
29+
* Set OPJLIKE_VSICURL_NATIVE=YES as a GDAL config option, or pass it as an
30+
* open option on the dataset, to opt in.
31+
*/
32+
static constexpr const char *OPJLIKE_VSICURL_NATIVE_OPT =
33+
"OPJLIKE_VSICURL_NATIVE";
34+
2635
typedef int JP2_COLOR_SPACE;
2736
typedef int JP2_PROG_ORDER;
2837

0 commit comments

Comments
 (0)