From ac963ad80808789ea5c059c18480751b52cd86ed Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 17 Oct 2016 14:18:45 -0700 Subject: [PATCH] Handle non-null terminated strings properly (flutter/engine#3138) The function we were using to initialize this NSString assumed that our UTF-8 data was null-terminated, which wasn't a valid assumption. Fixes https://github.com/flutter/flutter/issues/6359 --- engine/src/flutter/lib/ui/geometry.dart | 2 +- .../ios/framework/Source/application_messages_impl.mm | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/lib/ui/geometry.dart b/engine/src/flutter/lib/ui/geometry.dart index f60b982963..71197f2be6 100644 --- a/engine/src/flutter/lib/ui/geometry.dart +++ b/engine/src/flutter/lib/ui/geometry.dart @@ -1106,7 +1106,7 @@ class RRect { // Returns the minimum between min and scale to which radius1 and radius2 // should be scaled with in order not to exceed the limit. - double _getMin(double min, double radius1, double radius2, limit) { + double _getMin(double min, double radius1, double radius2, double limit) { double sum = radius1 + radius2; if (sum > limit && sum != 0.0) return math.min(min, limit / sum); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/application_messages_impl.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/application_messages_impl.mm index 92d89e9a81..cbfa881e5c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/application_messages_impl.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/application_messages_impl.mm @@ -35,9 +35,13 @@ void ApplicationMessagesImpl::AddBinding( void ApplicationMessagesImpl::HandlePlatformMessage( ftl::RefPtr message) { - NSString* string = [NSString stringWithUTF8String:message->data().data()]; - ftl::RefPtr completer = message->response(); + const auto& buffer = message->data(); + NSString* string = [[NSString alloc] initWithBytes:buffer.data() + length:buffer.size() + encoding:NSUTF8StringEncoding]; + [string autorelease]; + ftl::RefPtr completer = message->response(); { auto it = listeners_.find(message->name()); if (it != listeners_.end()) {