Fossil SCM

Performance optimization for /hexdump. Also, prevent /hexdump from working for robots, as robots like to download thousands of /hexdumps from servers and soak up CPU time and bandwidth, and I cannot think of any reason for a robot to actually need a hexdump.

drh 2021-01-10 01:40 trunk
Commit 60736abcf6b28b85746ad64a99ccbee3b6694ba744353326f02ff4534ab0fc57
1 file changed +37 -11
+37 -11
--- src/info.c
+++ src/info.c
@@ -1901,25 +1901,43 @@
19011901
zLine[k+2] = ' ';
19021902
}
19031903
}
19041904
zLine[53] = ' ';
19051905
zLine[54] = ' ';
1906
- for(j=0; j<16; j++){
1907
- k = j+55;
1906
+ cgi_append_content(zLine, 55);
1907
+ for(j=k=0; j<16; j++){
19081908
if( i+j<n ){
19091909
unsigned char c = x[i+j];
1910
- if( c>=0x20 && c<=0x7e ){
1911
- zLine[k] = c;
1910
+ if( c>'>' && c<=0x7e ){
1911
+ zLine[k++] = c;
1912
+ }else if( c=='>' ){
1913
+ zLine[k++] = '&';
1914
+ zLine[k++] = 'g';
1915
+ zLine[k++] = 't';
1916
+ zLine[k++] = ';';
1917
+ }else if( c=='<' ){
1918
+ zLine[k++] = '&';
1919
+ zLine[k++] = 'l';
1920
+ zLine[k++] = 't';
1921
+ zLine[k++] = ';';
1922
+ }else if( c=='&' ){
1923
+ zLine[k++] = '&';
1924
+ zLine[k++] = 'a';
1925
+ zLine[k++] = 'm';
1926
+ zLine[k++] = 'p';
1927
+ zLine[k++] = ';';
1928
+ }else if( c>=' ' ){
1929
+ zLine[k++] = c;
19121930
}else{
1913
- zLine[k] = '.';
1931
+ zLine[k++] = '.';
19141932
}
19151933
}else{
1916
- zLine[k] = 0;
1934
+ break;
19171935
}
19181936
}
1919
- zLine[71] = 0;
1920
- @ %h(zLine)
1937
+ zLine[k++] = '\n';
1938
+ cgi_append_content(zLine, k);
19211939
}
19221940
}
19231941
19241942
/*
19251943
** WEBPAGE: hexdump
@@ -1966,13 +1984,21 @@
19661984
object_description(rid, objdescFlags, 0, &downloadName);
19671985
style_submenu_element("Download", "%R/raw/%s?at=%T",
19681986
zUuid, file_tail(blob_str(&downloadName)));
19691987
@ <hr />
19701988
content_get(rid, &content);
1971
- @ <blockquote><pre>
1972
- hexdump(&content);
1973
- @ </pre></blockquote>
1989
+ if( !g.isHuman ){
1990
+ /* Prevent robots from running hexdump on megabyte-sized source files
1991
+ ** and there by eating up lots of CPU time and bandwidth. There is
1992
+ ** no good reason for a robot to need a hexdump. */
1993
+ @ <p>A hex dump of this file is not available.
1994
+ @ Please download the raw binary file and generate a hex dump yourself.</p>
1995
+ }else{
1996
+ @ <blockquote><pre>
1997
+ hexdump(&content);
1998
+ @ </pre></blockquote>
1999
+ }
19742000
style_finish_page();
19752001
}
19762002
19772003
/*
19782004
** Look for "ci" and "filename" query parameters. If found, try to
19792005
--- src/info.c
+++ src/info.c
@@ -1901,25 +1901,43 @@
1901 zLine[k+2] = ' ';
1902 }
1903 }
1904 zLine[53] = ' ';
1905 zLine[54] = ' ';
1906 for(j=0; j<16; j++){
1907 k = j+55;
1908 if( i+j<n ){
1909 unsigned char c = x[i+j];
1910 if( c>=0x20 && c<=0x7e ){
1911 zLine[k] = c;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1912 }else{
1913 zLine[k] = '.';
1914 }
1915 }else{
1916 zLine[k] = 0;
1917 }
1918 }
1919 zLine[71] = 0;
1920 @ %h(zLine)
1921 }
1922 }
1923
1924 /*
1925 ** WEBPAGE: hexdump
@@ -1966,13 +1984,21 @@
1966 object_description(rid, objdescFlags, 0, &downloadName);
1967 style_submenu_element("Download", "%R/raw/%s?at=%T",
1968 zUuid, file_tail(blob_str(&downloadName)));
1969 @ <hr />
1970 content_get(rid, &content);
1971 @ <blockquote><pre>
1972 hexdump(&content);
1973 @ </pre></blockquote>
 
 
 
 
 
 
 
 
1974 style_finish_page();
1975 }
1976
1977 /*
1978 ** Look for "ci" and "filename" query parameters. If found, try to
1979
--- src/info.c
+++ src/info.c
@@ -1901,25 +1901,43 @@
1901 zLine[k+2] = ' ';
1902 }
1903 }
1904 zLine[53] = ' ';
1905 zLine[54] = ' ';
1906 cgi_append_content(zLine, 55);
1907 for(j=k=0; j<16; j++){
1908 if( i+j<n ){
1909 unsigned char c = x[i+j];
1910 if( c>'>' && c<=0x7e ){
1911 zLine[k++] = c;
1912 }else if( c=='>' ){
1913 zLine[k++] = '&';
1914 zLine[k++] = 'g';
1915 zLine[k++] = 't';
1916 zLine[k++] = ';';
1917 }else if( c=='<' ){
1918 zLine[k++] = '&';
1919 zLine[k++] = 'l';
1920 zLine[k++] = 't';
1921 zLine[k++] = ';';
1922 }else if( c=='&' ){
1923 zLine[k++] = '&';
1924 zLine[k++] = 'a';
1925 zLine[k++] = 'm';
1926 zLine[k++] = 'p';
1927 zLine[k++] = ';';
1928 }else if( c>=' ' ){
1929 zLine[k++] = c;
1930 }else{
1931 zLine[k++] = '.';
1932 }
1933 }else{
1934 break;
1935 }
1936 }
1937 zLine[k++] = '\n';
1938 cgi_append_content(zLine, k);
1939 }
1940 }
1941
1942 /*
1943 ** WEBPAGE: hexdump
@@ -1966,13 +1984,21 @@
1984 object_description(rid, objdescFlags, 0, &downloadName);
1985 style_submenu_element("Download", "%R/raw/%s?at=%T",
1986 zUuid, file_tail(blob_str(&downloadName)));
1987 @ <hr />
1988 content_get(rid, &content);
1989 if( !g.isHuman ){
1990 /* Prevent robots from running hexdump on megabyte-sized source files
1991 ** and there by eating up lots of CPU time and bandwidth. There is
1992 ** no good reason for a robot to need a hexdump. */
1993 @ <p>A hex dump of this file is not available.
1994 @ Please download the raw binary file and generate a hex dump yourself.</p>
1995 }else{
1996 @ <blockquote><pre>
1997 hexdump(&content);
1998 @ </pre></blockquote>
1999 }
2000 style_finish_page();
2001 }
2002
2003 /*
2004 ** Look for "ci" and "filename" query parameters. If found, try to
2005

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button