drupflare/worker - v1.0.4
    Preparing search index...

    Variable ZLIB_FIXConst

    ZLIB_FIX: "\n// NO eval(), unlike mb-fix. A conditional declaration colliding with an internal function is\n// deferred to runtime, so this compiles clean on a build that HAS zlib and the branch simply\n// does not run -- verified with php -l plus a run on a host with the extension loaded. Plain\n// PHP is what lets tests/node/php-fragments.spec.ts see inside the body at all.\n\n// FIRST BLOCK: the bridge itself plus the one capability ext-zlib does not have. Nothing here\n// collides with an internal function, so it is declared on every build.\nif (!function_exists('cfw_zlib_dict')) {\n\t$__cfw_zlib = function_exists('vrzno_env') ? vrzno_env('cfwZlib') : null;\n\tif ($__cfw_zlib !== null) {\n\t\t$GLOBALS['__cfw_zlib'] = $__cfw_zlib;\n\n\t\t/**\n\t\t * Runs one op over the bridge.\n\t\t *\n\t\t * @param string $op\n\t\t * gzip, gunzip, zlib, unzlib, deflate or inflate.\n\t\t * @param string $data\n\t\t * The bytes to transform.\n\t\t * @param int $level\n\t\t * A zlib level, or -1 for the default.\n\t\t * @param string $dict\n\t\t * A preset dictionary, or an empty string for none.\n\t\t *\n\t\t * @return array{ok: bool, data?: string, error?: string}\n\t\t * ['ok' => true, 'data' => string] or ['ok' => false, 'error' => string].\n\t\t */\n\t\tfunction cfw_zlib($op, $data, $level = -1, $dict = ''): array\n\t\t{\n\t\t\t$fn = $GLOBALS['__cfw_zlib'];\n\t\t\t$reply = json_decode(\n\t\t\t\t$fn(\n\t\t\t\t\tjson_encode([\n\t\t\t\t\t\t'op' => $op,\n\t\t\t\t\t\t'b64' => base64_encode((string) $data),\n\t\t\t\t\t\t'level' => $level,\n\t\t\t\t\t\t'dict' => base64_encode((string) $dict),\n\t\t\t\t\t]),\n\t\t\t\t),\n\t\t\t\ttrue,\n\t\t\t);\n\t\t\tif (!is_array($reply) || ($reply['ok'] ?? false) !== true) {\n\t\t\t\t$why = is_array($reply)\n\t\t\t\t\t? (string) ($reply['error'] ?? 'no reason given')\n\t\t\t\t\t: 'unreadable reply';\n\t\t\t\treturn ['ok' => false, 'error' => $why];\n\t\t\t}\n\t\t\t$out = base64_decode((string) ($reply['b64'] ?? ''), true);\n\t\t\tif ($out === false) {\n\t\t\t\treturn ['ok' => false, 'error' => 'reply was not base64'];\n\t\t\t}\n\t\t\treturn ['ok' => true, 'data' => $out];\n\t\t}\n\n\t\t/**\n\t\t * Raises the diagnostic ext-zlib raises, then answers FALSE like it does.\n\t\t *\n\t\t * @param string $name\n\t\t * The PHP function that failed.\n\t\t * @param string $reason\n\t\t * What ext-zlib would have said.\n\t\t */\n\t\tfunction cfw_zlib_fail($name, $reason): false\n\t\t{\n\t\t\ttrigger_error($name . '(): ' . $reason, E_USER_WARNING);\n\t\t\treturn false;\n\t\t}\n\n\t\t/**\n\t\t * Compresses or decompresses against a preset dictionary.\n\t\t *\n\t\t * NOT shaped like a gz* function: PHP has never had a dictionary\n\t\t * parameter on gzcompress(), so widening one of those signatures would make a host-only\n\t\t * argument look like part of the language. function_exists('cfw_zlib_dict') is the feature\n\t\t * test a caller uses.\n\t\t *\n\t\t * $op is 'zlib' to compress and 'unzlib' to decompress; the output is an ordinary zlib\n\t\t * stream with FDICT set. gzip and the raw pair are refused, because neither has anywhere\n\t\t * to record the dictionary's checksum -- so a wrong dictionary would decode to plausible\n\t\t * garbage instead of failing.\n\t\t *\n\t\t * @param string $op\n\t\t * zlib or unzlib.\n\t\t * @param string $data\n\t\t * The bytes to transform.\n\t\t * @param string $dict\n\t\t * The preset dictionary.\n\t\t * @param int $level\n\t\t * A zlib level, or -1 for the default.\n\t\t *\n\t\t * @return string|false\n\t\t * The bytes, or FALSE with an E_USER_WARNING, matching the gz* functions.\n\t\t */\n\t\tfunction cfw_zlib_dict($op, $data, $dict, $level = -1)\n\t\t{\n\t\t\tif ($op !== 'zlib' && $op !== 'unzlib') {\n\t\t\t\treturn cfw_zlib_fail(\n\t\t\t\t\t'cfw_zlib_dict',\n\t\t\t\t\t\"op '\" .\n\t\t\t\t\t\t$op .\n\t\t\t\t\t\t\"' takes no preset dictionary; use zlib to compress or unzlib to decompress\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif ((string) $dict === '') {\n\t\t\t\treturn cfw_zlib_fail('cfw_zlib_dict', 'the dictionary is empty');\n\t\t\t}\n\t\t\t$r = cfw_zlib($op, $data, $level, $dict);\n\t\t\treturn $r['ok'] ? $r['data'] : cfw_zlib_fail('cfw_zlib_dict', $r['error']);\n\t\t}\n\t}\n}\n\n// SECOND BLOCK: the six names ext-zlib owns. Inert wherever the extension is loaded, which\n// includes the shipping binary.\nif (!extension_loaded('zlib') && !function_exists('cfw_zlib_installed')) {\n\t$__cfw_zlib = function_exists('vrzno_env') ? vrzno_env('cfwZlib') : null;\n\tif ($__cfw_zlib !== null) {\n\t\t$GLOBALS['__cfw_zlib'] = $__cfw_zlib;\n\n\t\t// ext-zlib declares these, so they vanish with it. FORCE_GZIP is read by AssetDumper and\n\t\t// would be an Error(\"Undefined constant\") without this line.\n\t\tif (!defined('ZLIB_ENCODING_RAW')) {\n\t\t\tdefine('ZLIB_ENCODING_RAW', -15);\n\t\t}\n\t\tif (!defined('ZLIB_ENCODING_DEFLATE')) {\n\t\t\tdefine('ZLIB_ENCODING_DEFLATE', 15);\n\t\t}\n\t\tif (!defined('ZLIB_ENCODING_GZIP')) {\n\t\t\tdefine('ZLIB_ENCODING_GZIP', 31);\n\t\t}\n\t\tif (!defined('FORCE_DEFLATE')) {\n\t\t\tdefine('FORCE_DEFLATE', 15);\n\t\t}\n\t\tif (!defined('FORCE_GZIP')) {\n\t\t\tdefine('FORCE_GZIP', 31);\n\t\t}\n\n\t\tfunction cfw_zlib_installed(): bool\n\t\t{\n\t\t\treturn true;\n\t\t}\n\n\t\t/**\n\t\t * Refuses a level outside -1..9, with the ValueError ext-zlib throws.\n\t\t *\n\t\t * @param string $name\n\t\t * The PHP function being called.\n\t\t * @param int $level\n\t\t * The level the caller passed.\n\t\t *\n\t\t * @return int\n\t\t * The level, unchanged.\n\t\t */\n\t\tfunction cfw_zlib_level($name, $level)\n\t\t{\n\t\t\tif ($level < -1 || $level > 9) {\n\t\t\t\tthrow new ValueError($name . \"(): Argument #2 (\\$level) must be between -1 and 9\");\n\t\t\t}\n\t\t\treturn $level;\n\t\t}\n\n\t\t/**\n\t\t * The container an encoding names.\n\t\t *\n\t\t * All three encoders accept all three encodings and emit that container -- measured on\n\t\t * 8.5.7, gzcompress(x, 9, ZLIB_ENCODING_GZIP) is byte-identical to\n\t\t * gzencode(x, 9, FORCE_GZIP) -- so the three share one mapping.\n\t\t *\n\t\t * @param string $name\n\t\t * The PHP function being called.\n\t\t * @param int $encoding\n\t\t * A ZLIB_ENCODING_* value.\n\t\t */\n\t\tfunction cfw_zlib_encoding($name, $encoding): string\n\t\t{\n\t\t\tif ($encoding === 31) {\n\t\t\t\treturn 'gzip';\n\t\t\t}\n\t\t\tif ($encoding === 15) {\n\t\t\t\treturn 'zlib';\n\t\t\t}\n\t\t\tif ($encoding === -15) {\n\t\t\t\treturn 'deflate';\n\t\t\t}\n\t\t\tthrow new ValueError(\n\t\t\t\t$name .\n\t\t\t\t\t\"(): Argument #3 (\\$encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE\",\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Applies $max_length the way zlib does, which is NOT a truncation.\n\t\t *\n\t\t * Measured: gzuncompress(gzcompress('hello world'), 5) is FALSE, not 'hello'. zlib fails\n\t\t * the inflate when its output buffer is too small, so a cap below the payload is a data\n\t\t * error rather than a short read. 0 means no cap.\n\t\t *\n\t\t * @param string $name\n\t\t * The PHP function being called.\n\t\t * @param string $data\n\t\t * The inflated bytes.\n\t\t * @param int $max_length\n\t\t * The cap, or 0 for none.\n\t\t *\n\t\t * @return string|false\n\t\t * The bytes, or FALSE with an E_USER_WARNING when the cap was exceeded.\n\t\t */\n\t\tfunction cfw_zlib_cap($name, $data, $max_length)\n\t\t{\n\t\t\tif ($max_length > 0 && strlen($data) > $max_length) {\n\t\t\t\treturn cfw_zlib_fail($name, 'data error');\n\t\t\t}\n\t\t\treturn $data;\n\t\t}\n\n\t\t// the encoding defaults are spelled as ints rather than as the constants defined above, so\n\t\t// the signature does not depend on when a define() ran\n\t\t/**\n\t\t * @param string $data\n\t\t * The bytes to compress.\n\t\t * @param int $level\n\t\t * A zlib level, or -1 for the default.\n\t\t * @param int $encoding\n\t\t * A ZLIB_ENCODING_* value.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzencode($data, $level = -1, $encoding = 31)\n\t\t{\n\t\t\t$op = cfw_zlib_encoding('gzencode', $encoding);\n\t\t\tcfw_zlib_level('gzencode', $level);\n\t\t\t$r = cfw_zlib($op, $data, $level);\n\t\t\treturn $r['ok'] ? $r['data'] : cfw_zlib_fail('gzencode', $r['error']);\n\t\t}\n\n\t\t/**\n\t\t * @param string $data\n\t\t * The bytes to compress.\n\t\t * @param int $level\n\t\t * A zlib level, or -1 for the default.\n\t\t * @param int $encoding\n\t\t * A ZLIB_ENCODING_* value.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzcompress($data, $level = -1, $encoding = 15)\n\t\t{\n\t\t\t$op = cfw_zlib_encoding('gzcompress', $encoding);\n\t\t\tcfw_zlib_level('gzcompress', $level);\n\t\t\t$r = cfw_zlib($op, $data, $level);\n\t\t\treturn $r['ok'] ? $r['data'] : cfw_zlib_fail('gzcompress', $r['error']);\n\t\t}\n\n\t\t/**\n\t\t * @param string $data\n\t\t * The bytes to compress.\n\t\t * @param int $level\n\t\t * A zlib level, or -1 for the default.\n\t\t * @param int $encoding\n\t\t * A ZLIB_ENCODING_* value.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzdeflate($data, $level = -1, $encoding = -15)\n\t\t{\n\t\t\t$op = cfw_zlib_encoding('gzdeflate', $encoding);\n\t\t\tcfw_zlib_level('gzdeflate', $level);\n\t\t\t$r = cfw_zlib($op, $data, $level);\n\t\t\treturn $r['ok'] ? $r['data'] : cfw_zlib_fail('gzdeflate', $r['error']);\n\t\t}\n\n\t\t/**\n\t\t * @param string $data\n\t\t * The gzip stream.\n\t\t * @param int $max_length\n\t\t * The cap on the inflated size, or 0 for none.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzdecode($data, $max_length = 0)\n\t\t{\n\t\t\t$r = cfw_zlib('gunzip', $data);\n\t\t\tif (!$r['ok']) {\n\t\t\t\treturn cfw_zlib_fail('gzdecode', 'data error');\n\t\t\t}\n\t\t\treturn cfw_zlib_cap('gzdecode', $r['data'], $max_length);\n\t\t}\n\n\t\t/**\n\t\t * @param string $data\n\t\t * The zlib stream.\n\t\t * @param int $max_length\n\t\t * The cap on the inflated size, or 0 for none.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzuncompress($data, $max_length = 0)\n\t\t{\n\t\t\t$r = cfw_zlib('unzlib', $data);\n\t\t\tif (!$r['ok']) {\n\t\t\t\treturn cfw_zlib_fail('gzuncompress', 'data error');\n\t\t\t}\n\t\t\treturn cfw_zlib_cap('gzuncompress', $r['data'], $max_length);\n\t\t}\n\n\t\t/**\n\t\t * @param string $data\n\t\t * The raw deflate stream.\n\t\t * @param int $max_length\n\t\t * The cap on the inflated size, or 0 for none.\n\t\t *\n\t\t * @return string|false\n\t\t */\n\t\tfunction gzinflate($data, $max_length = 0)\n\t\t{\n\t\t\t$r = cfw_zlib('inflate', $data);\n\t\t\tif (!$r['ok']) {\n\t\t\t\treturn cfw_zlib_fail('gzinflate', 'data error');\n\t\t\t}\n\t\t\treturn cfw_zlib_cap('gzinflate', $r['data'], $max_length);\n\t\t}\n\t}\n}\n" = ZLIB_FIX_PHP

    The PHP half: the six gz* functions, the encoding constants and cfw_zlib_dict().

    The gz* functions are defined only when the bridge resolves (a stub returning false would let AssetDumper serve a zero-byte .gz as gzip). Stream functions and compress.zlib:// are not covered. cfw_zlib_dict() sits outside the extension guard: the shipping binary loads ext-zlib, which has no dictionary support.