mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-26 04:35:39 +03:00
thttpd erroneously treats these files as a compressed transfer encoding rather than as a content type. this causes conforming http clients to strip the compression and save a decompressed version when downloading. since this was historically a common httpd bug, some web browsers work around the problem by detecting the .gz extension and ignoring the server's reported transfer encoding, but others, including wget 1.19.2, save a decompressed file, breaking file integrity checking (based on a hash or signature of the original compressed file) and breaking scripts which pass the -z option to tar when extracting. add a patch which removes thttpd's support for extension-based content transfer encodings, and adds the missing mime types for gzip and compress. the patch has been written to be minimally invasive to the program logic, and thus leaves a for loop that breaks on the first iteration rather than rewriting it.
169 lines
5 KiB
Diff
169 lines
5 KiB
Diff
diff --git a/Makefile.in b/Makefile.in
|
|
index ded71e0..f9a6bc1 100644
|
|
--- a/Makefile.in
|
|
+++ b/Makefile.in
|
|
@@ -68,7 +68,7 @@ OBJ = $(SRC:.c=.o) @LIBOBJS@
|
|
|
|
ALL = thttpd
|
|
|
|
-GENHDR = mime_encodings.h mime_types.h
|
|
+GENHDR = mime_types.h
|
|
|
|
CLEANFILES = $(ALL) $(OBJ) $(GENSRC) $(GENHDR)
|
|
|
|
@@ -81,12 +81,6 @@ thttpd: $(OBJ)
|
|
@rm -f $@
|
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) $(NETLIBS)
|
|
|
|
-mime_encodings.h: mime_encodings.txt
|
|
- rm -f mime_encodings.h
|
|
- sed < mime_encodings.txt > mime_encodings.h \
|
|
- -e 's/#.*//' -e 's/[ ]*$$//' -e '/^$$/d' \
|
|
- -e 's/[ ][ ]*/", 0, "/' -e 's/^/{ "/' -e 's/$$/", 0 },/'
|
|
-
|
|
mime_types.h: mime_types.txt
|
|
rm -f mime_types.h
|
|
sed < mime_types.txt > mime_types.h \
|
|
@@ -157,14 +151,14 @@ tar:
|
|
rm -rf $$name ; \
|
|
mkdir $$name ; \
|
|
tar cf - `cat FILES` | ( cd $$name ; tar xfBp - ) ; \
|
|
- chmod 644 $$name/Makefile.in $$name/config.h $$name/mime_encodings.txt $$name/mime_types.txt ; \
|
|
+ chmod 644 $$name/Makefile.in $$name/config.h $$name/mime_types.txt ; \
|
|
chmod 755 $$name/cgi-bin $$name/cgi-src $$name/contrib $$name/contrib/redhat-rpm $$name/extras $$name/scripts ; \
|
|
tar cf $$name.tar $$name ; \
|
|
rm -rf $$name ; \
|
|
gzip $$name.tar
|
|
|
|
thttpd.o: config.h version.h libhttpd.h fdwatch.h mmc.h timers.h match.h
|
|
-libhttpd.o: config.h version.h libhttpd.h mime_encodings.h mime_types.h \
|
|
+libhttpd.o: config.h version.h libhttpd.h mime_types.h \
|
|
mmc.h timers.h match.h tdate_parse.h
|
|
fdwatch.o: fdwatch.h
|
|
mmc.o: mmc.h libhttpd.h
|
|
diff --git a/libhttpd.c b/libhttpd.c
|
|
index 3814e6a..bbb4e14 100644
|
|
--- a/libhttpd.c
|
|
+++ b/libhttpd.c
|
|
@@ -2506,10 +2506,6 @@ struct mime_entry {
|
|
char* val;
|
|
size_t val_len;
|
|
};
|
|
-static struct mime_entry enc_tab[] = {
|
|
-#include "mime_encodings.h"
|
|
- };
|
|
-static const int n_enc_tab = sizeof(enc_tab) / sizeof(*enc_tab);
|
|
static struct mime_entry typ_tab[] = {
|
|
#include "mime_types.h"
|
|
};
|
|
@@ -2533,15 +2529,9 @@ init_mime( void )
|
|
int i;
|
|
|
|
/* Sort the tables so we can do binary search. */
|
|
- qsort( enc_tab, n_enc_tab, sizeof(*enc_tab), ext_compare );
|
|
qsort( typ_tab, n_typ_tab, sizeof(*typ_tab), ext_compare );
|
|
|
|
/* Fill in the lengths. */
|
|
- for ( i = 0; i < n_enc_tab; ++i )
|
|
- {
|
|
- enc_tab[i].ext_len = strlen( enc_tab[i].ext );
|
|
- enc_tab[i].val_len = strlen( enc_tab[i].val );
|
|
- }
|
|
for ( i = 0; i < n_typ_tab; ++i )
|
|
{
|
|
typ_tab[i].ext_len = strlen( typ_tab[i].ext );
|
|
@@ -2561,14 +2551,12 @@ figure_mime( httpd_conn* hc )
|
|
char* prev_dot;
|
|
char* dot;
|
|
char* ext;
|
|
- int me_indexes[100], n_me_indexes;
|
|
- size_t ext_len, encodings_len;
|
|
+ size_t ext_len;
|
|
int i, top, bot, mid;
|
|
int r;
|
|
char* default_type = "text/plain; charset=%s";
|
|
|
|
/* Peel off encoding extensions until there aren't any more. */
|
|
- n_me_indexes = 0;
|
|
for ( prev_dot = &hc->expnfilename[strlen(hc->expnfilename)]; ; prev_dot = dot )
|
|
{
|
|
for ( dot = prev_dot - 1; dot >= hc->expnfilename && *dot != '.'; --dot )
|
|
@@ -2583,25 +2571,7 @@ figure_mime( httpd_conn* hc )
|
|
}
|
|
ext = dot + 1;
|
|
ext_len = prev_dot - ext;
|
|
- /* Search the encodings table. Linear search is fine here, there
|
|
- ** are only a few entries.
|
|
- */
|
|
- for ( i = 0; i < n_enc_tab; ++i )
|
|
- {
|
|
- if ( ext_len == enc_tab[i].ext_len && strncasecmp( ext, enc_tab[i].ext, ext_len ) == 0 )
|
|
- {
|
|
- if ( n_me_indexes < sizeof(me_indexes)/sizeof(*me_indexes) )
|
|
- {
|
|
- me_indexes[n_me_indexes] = i;
|
|
- ++n_me_indexes;
|
|
- }
|
|
- goto next;
|
|
- }
|
|
- }
|
|
- /* No encoding extension found. Break and look for a type extension. */
|
|
break;
|
|
-
|
|
- next: ;
|
|
}
|
|
|
|
/* Binary search for a matching type extension. */
|
|
@@ -2632,20 +2602,6 @@ figure_mime( httpd_conn* hc )
|
|
|
|
/* The last thing we do is actually generate the mime-encoding header. */
|
|
hc->encodings[0] = '\0';
|
|
- encodings_len = 0;
|
|
- for ( i = n_me_indexes - 1; i >= 0; --i )
|
|
- {
|
|
- httpd_realloc_str(
|
|
- &hc->encodings, &hc->maxencodings,
|
|
- encodings_len + enc_tab[me_indexes[i]].val_len + 1 );
|
|
- if ( hc->encodings[0] != '\0' )
|
|
- {
|
|
- (void) strcpy( &hc->encodings[encodings_len], "," );
|
|
- ++encodings_len;
|
|
- }
|
|
- (void) strcpy( &hc->encodings[encodings_len], enc_tab[me_indexes[i]].val );
|
|
- encodings_len += enc_tab[me_indexes[i]].val_len;
|
|
- }
|
|
|
|
}
|
|
|
|
diff --git a/mime_encodings.txt b/mime_encodings.txt
|
|
deleted file mode 100644
|
|
index 2d3952d..0000000
|
|
--- a/mime_encodings.txt
|
|
+++ /dev/null
|
|
@@ -1,8 +0,0 @@
|
|
-# mime_encodings.txt
|
|
-#
|
|
-# A list of file extensions followed by the corresponding MIME encoding.
|
|
-# Extensions not found in the table proceed to the mime_types table.
|
|
-
|
|
-Z compress
|
|
-gz gzip
|
|
-uu x-uuencode
|
|
diff --git a/mime_types.txt b/mime_types.txt
|
|
index d4725d9..3d7ccbd 100644
|
|
--- a/mime_types.txt
|
|
+++ b/mime_types.txt
|
|
@@ -50,6 +50,7 @@ fh7 image/x-freehand
|
|
fhc image/x-freehand
|
|
gif image/gif
|
|
gtar application/x-gtar
|
|
+gz application/gzip
|
|
hdf application/x-hdf
|
|
hqx application/mac-binhex40
|
|
htm text/html; charset=%s
|
|
@@ -195,4 +196,5 @@ xpm image/x-xpixmap
|
|
xsl text/xml; charset=%s
|
|
xwd image/x-xwindowdump
|
|
xyz chemical/x-xyz
|
|
+Z application/x-compress
|
|
zip application/zip
|