lib/protocol/http1/body/chunked.rb in protocol-http1-0.15.0 vs lib/protocol/http1/body/chunked.rb in protocol-http1-0.15.1
- old
+ new
@@ -33,15 +33,23 @@
end
super
end
+ VALID_CHUNK_LENGTH = /\A[0-9a-fA-F]+\z/
+
# Follows the procedure outlined in https://tools.ietf.org/html/rfc7230#section-4.1.3
def read
return nil if @finished
+ length, extensions = read_line.split(";", 2)
+
+ unless length =~ VALID_CHUNK_LENGTH
+ raise BadRequest, "Invalid chunk length: #{length.dump}"
+ end
+
# It is possible this line contains chunk extension, so we use `to_i` to only consider the initial integral part:
- length = read_line.to_i(16)
+ length = Integer(length, 16)
if length == 0
@finished = true
read_trailer