Skip to content

Commit 3b87c1d

Browse files
authored
add qlhelp file and example
1 parent 7c2b19b commit 3b87c1d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>
7+
Decompression of user-controlled data without taking proper precaution can
8+
result in uncontrolled and massive decompression on the server, resulting
9+
in a denial of service.
10+
</p>
11+
</overview>
12+
<recommendation>
13+
<p>
14+
When decompressing files supplied by the user, make sure that you're checking
15+
the size of the incoming data chunks before writing to an output.
16+
</p>
17+
</recommendation>
18+
<example>
19+
<p>
20+
In this example, the size of the input buffer chunks and total size are checked before each chunk is written to the output.
21+
</p>
22+
<sample src="examples/decompress.rb" />
23+
</example>
24+
25+
<references>
26+
<a href="https://cwe.mitre.org/data/definitions/409.html">https://cwe.mitre.org/data/definitions/409.html</a>
27+
</references>
28+
</qhelp>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class UsersController < ActionController::Base
2+
def example_zlib_inflate
3+
MAX_ALLOWED_CHUNK_SIZE = 256
4+
MAX_ALLOWED_TOTAL_SIZE = 1024
5+
6+
user_data = params[:data]
7+
output = []
8+
outsize = 0
9+
10+
Zlib::Inflate.inflate(user_data) { |chunk|
11+
outsize += chunk.size
12+
if chunk.size < MAX_ALLOWED_CHUNK_SIZE && outsize < MAX_ALLOWED_TOTAL_SIZE
13+
output << chunk
14+
end
15+
}
16+
end
17+
end

0 commit comments

Comments
 (0)