[Scummvm-git-logs] scummvm master -> 3677c91606a56e3571ebd5831c7b03f32e50ec41

lephilousophe noreply at scummvm.org
Sun May 18 21:04:16 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
3677c91606 COMMON: Fix JSON parsing of unicode strings


Commit: 3677c91606a56e3571ebd5831c7b03f32e50ec41
    https://github.com/scummvm/scummvm/commit/3677c91606a56e3571ebd5831c7b03f32e50ec41
Author: Christian Kündig (christian at kuendig.info)
Date: 2025-05-18T23:04:13+02:00

Commit Message:
COMMON: Fix JSON parsing of unicode strings

Changed paths:
    backends/networking/curl/curljsonrequest.cpp
    backends/networking/sdl_net/handlers/connectcloudhandler.cpp
    common/formats/json.cpp
    common/formats/json.h
    gui/cloudconnectionwizard.cpp


diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index dfa21223d77..dad77c25617 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -49,7 +49,7 @@ void CurlJsonRequest::handle() {
 				warning("CurlJsonRequest: unable to write all the bytes into MemoryWriteStreamDynamic");
 
 		if (_stream->eos()) {
-			char *contents = Common::JSON::untaintContents(_contentsStream);
+			char *contents = Common::JSON::zeroTerminateContents(_contentsStream);
 			Common::JSONValue *json = Common::JSON::parse(contents);
 			if (json) {
 				finishJson(json); //it's JSON even if's not 200 OK? That's fine!..
diff --git a/backends/networking/sdl_net/handlers/connectcloudhandler.cpp b/backends/networking/sdl_net/handlers/connectcloudhandler.cpp
index fe8407dee40..1c161f5a515 100644
--- a/backends/networking/sdl_net/handlers/connectcloudhandler.cpp
+++ b/backends/networking/sdl_net/handlers/connectcloudhandler.cpp
@@ -109,7 +109,7 @@ void ConnectCloudClientHandler::handle(Client *client) {
 	if (!client->readContent(&_clientContent))
 		return;
 
-	char *contents = Common::JSON::untaintContents(_clientContent);
+	char *contents = Common::JSON::zeroTerminateContents(_clientContent);
 	Common::JSONValue *json = Common::JSON::parse(contents);
 	if (json == nullptr) {
 		handleError(*client, "Not Acceptable", 406);
diff --git a/common/formats/json.cpp b/common/formats/json.cpp
index e29ffd7c850..f5b5e00ead7 100644
--- a/common/formats/json.cpp
+++ b/common/formats/json.cpp
@@ -63,23 +63,11 @@ namespace Common {
 */
 JSON::JSON() {}
 
-char *JSON::untaintContents(Common::MemoryWriteStreamDynamic &stream) {
+char *JSON::zeroTerminateContents(Common::MemoryWriteStreamDynamic &stream) {
 	// write one more byte in the end
 	byte zero[1] = {0};
 	stream.write(zero, 1);
-
-	// replace all "bad" bytes with '.' character
 	byte *result = stream.getData();
-	uint32 size = stream.size();
-	for (uint32 i = 0; i < size; ++i) {
-		if (result[i] == '\n')
-			result[i] = ' '; // yeah, kinda stupid
-		else if (result[i] < 0x20 || result[i] > 0x7f)
-			result[i] = '.';
-	}
-
-	// make it zero-terminated string
-	result[size - 1] = '\0';
 
 	return (char *)result;
 }
@@ -223,7 +211,7 @@ bool JSON::extractString(const char **data, String &str) {
 		}
 
 		// Disallowed char?
-		else if (next_char < ' ' && next_char != '\t') {
+		else if (next_char > 0 && next_char < ' ' && next_char != '\t') {
 			// SPEC Violation: Allow tabs due to real world cases
 			return false;
 		}
diff --git a/common/formats/json.h b/common/formats/json.h
index f0ef4e392e1..8dcb040e512 100644
--- a/common/formats/json.h
+++ b/common/formats/json.h
@@ -153,7 +153,7 @@ class JSON {
 
 public:
 	/** Prepares raw bytes in a given stream to be parsed with Common::JSON::parse(). */
-	static char *untaintContents(Common::MemoryWriteStreamDynamic &stream);
+	static char *zeroTerminateContents(Common::MemoryWriteStreamDynamic &stream);
 
 	static JSONValue *parse(const char *data);
 	static String stringify(const JSONValue *value);
diff --git a/gui/cloudconnectionwizard.cpp b/gui/cloudconnectionwizard.cpp
index b29e96ca294..0034bdff05f 100644
--- a/gui/cloudconnectionwizard.cpp
+++ b/gui/cloudconnectionwizard.cpp
@@ -526,7 +526,7 @@ void CloudConnectionWizard::manualModeConnect() {
 	// parse JSON and display message if failed
 	Common::MemoryWriteStreamDynamic jsonStream(DisposeAfterUse::YES);
 	jsonStream.write(code.c_str(), code.size());
-	char *contents = Common::JSON::untaintContents(jsonStream);
+	char *contents = Common::JSON::zeroTerminateContents(jsonStream);
 	Common::JSONValue *json = Common::JSON::parse(contents);
 
 	// pass JSON to the manager




More information about the Scummvm-git-logs mailing list