Browse Source

Fix http limitation for large "content-length"

When a request was issued to a server that returned "content-length" header
whose value was greater than that of an "int" we ran into overflow
problems. The fix for this was rather simple by increasing the data
type to `int64_t`

(cherry picked from commit 69a532414c87bfbc7465c45b92f7315d3edf206b)
Cnidarias 3 years ago
parent
commit
e3292633be
2 changed files with 3 additions and 3 deletions
  1. 1 1
      core/io/http_client.cpp
  2. 2 2
      core/io/http_client.h

+ 1 - 1
core/io/http_client.cpp

@@ -555,7 +555,7 @@ Error HTTPClient::poll() {
 							continue;
 						}
 						if (s.begins_with("content-length:")) {
-							body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int();
+							body_size = s.substr(s.find(":") + 1, s.length()).strip_edges().to_int64();
 							body_left = body_size;
 
 						} else if (s.begins_with("transfer-encoding:")) {

+ 2 - 2
core/io/http_client.h

@@ -180,8 +180,8 @@ private:
 	Vector<uint8_t> chunk;
 	int chunk_left;
 	bool chunk_trailer_part;
-	int body_size;
-	int body_left;
+	int64_t body_size;
+	int64_t body_left;
 	bool read_until_eof;
 
 	Ref<StreamPeerTCP> tcp_connection;