-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Disable decompression in mod_mime_magic by default #623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
notroj
wants to merge
1
commit into
apache:trunk
Choose a base branch
from
notroj:disable-magic
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,7 @@ typedef struct { | |
| const char *magicfile; /* where magic be found */ | ||
| struct magic *magic; /* head of magic config list */ | ||
| struct magic *last; | ||
| int decompression_enabled; /* whether to decompress files for content detection */ | ||
| } magic_server_config_rec; | ||
|
|
||
| /* per-request info */ | ||
|
|
@@ -472,8 +473,11 @@ module AP_MODULE_DECLARE_DATA mime_magic_module; | |
|
|
||
| static void *create_magic_server_config(apr_pool_t *p, server_rec *d) | ||
| { | ||
| magic_server_config_rec *conf; | ||
| /* allocate the config - use pcalloc because it needs to be zeroed */ | ||
| return apr_pcalloc(p, sizeof(magic_server_config_rec)); | ||
| conf = apr_pcalloc(p, sizeof(magic_server_config_rec)); | ||
| conf->decompression_enabled = 0; /* disabled by default */ | ||
| return conf; | ||
| } | ||
|
|
||
| static void *merge_magic_server_config(apr_pool_t *p, void *basev, void *addv) | ||
|
|
@@ -484,6 +488,7 @@ static void *merge_magic_server_config(apr_pool_t *p, void *basev, void *addv) | |
| apr_palloc(p, sizeof(magic_server_config_rec)); | ||
|
|
||
| new->magicfile = add->magicfile ? add->magicfile : base->magicfile; | ||
| new->decompression_enabled = add->decompression_enabled; | ||
| new->magic = NULL; | ||
| new->last = NULL; | ||
| return new; | ||
|
|
@@ -502,6 +507,19 @@ static const char *set_magicfile(cmd_parms *cmd, void *dummy, const char *arg) | |
| return NULL; | ||
| } | ||
|
|
||
| static const char *set_decompression(cmd_parms *cmd, void *dummy, int arg) | ||
| { | ||
| magic_server_config_rec *conf = (magic_server_config_rec *) | ||
| ap_get_module_config(cmd->server->module_config, | ||
| &mime_magic_module); | ||
|
|
||
| if (!conf) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary, that can never return NULL (it's an array lookup). |
||
| return MODNAME ": server structure not allocated"; | ||
| } | ||
| conf->decompression_enabled = arg; | ||
| return NULL; | ||
| } | ||
|
|
||
| /* | ||
| * configuration file commands - exported to Apache API | ||
| */ | ||
|
|
@@ -510,6 +528,13 @@ static const command_rec mime_magic_cmds[] = | |
| { | ||
| AP_INIT_TAKE1("MimeMagicFile", set_magicfile, NULL, RSRC_CONF, | ||
| "Path to MIME Magic file (in file(1) format)"), | ||
| AP_INIT_FLAG("MimeMagicDecompression", set_decompression, NULL, RSRC_CONF, | ||
| "Enable decompression of compressed files for content type detection " | ||
| "(Off by default). WARNING: This feature is NOT RFC-compliant, can be " | ||
| "unpredictable, breaks content integrity (clients will decompress files " | ||
| "causing checksum mismatches), impacts performance (fork/exec overhead), " | ||
| "and is unsafe (passes untrusted data to external gzip binary). " | ||
| "Use only if you understand these risks."), | ||
| {NULL} | ||
| }; | ||
|
|
||
|
|
@@ -878,10 +903,13 @@ static int magic_process(request_rec *r) | |
| static int tryit(request_rec *r, unsigned char *buf, apr_size_t nb, | ||
| int checkzmagic) | ||
| { | ||
| magic_server_config_rec *conf = (magic_server_config_rec *) | ||
| ap_get_module_config(r->server->module_config, &mime_magic_module); | ||
|
|
||
| /* | ||
| * Try compression stuff | ||
| * Try compression stuff (only if decompression is enabled) | ||
| */ | ||
| if (checkzmagic == 1) { | ||
| if (checkzmagic == 1 && conf && conf->decompression_enabled) { | ||
| if (zmagic(r, buf, nb) == 1) | ||
| return OK; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the setting doesn't inherit properly across vhosts. The simplest way to do this properly is to have ->decomp_enabled default to an "UNSET" macro defined as -1, and then use a ternary operator to inherit in the merge
= (add->decompress_enabled != UNSET) ? add->decompress_enabled : base->decompress_enabled. And also adjust the code that uses the field to special-case theUNSETvalue