Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect string length passed to yaml_document_add_scalar() in __YAMLSerializationAddObject() #28

Open
TheGS opened this issue Apr 26, 2018 · 1 comment

Comments

@TheGS
Copy link

TheGS commented Apr 26, 2018

In __YAMLSerializationAddObject(), there is a call to yaml_document_add_scalar() with a pointer to the UTF8 form of the NSString, but the number of Unicode characters is used as the byte length of that UTF8 string. This will definitely be incorrect if the string has any characters that require more than 1 byte to represent in UTF8. In any case, since -[NSString UTF8String] returns a C string, it's sufficient to use a value of -1... code in yaml_document_add_scalar() will detect this and call strlen() on the C string to get the correct string length.

@mirek
Copy link
Owner

mirek commented Apr 26, 2018

Absolutely

result = yaml_document_add_scalar(document, NULL, (yaml_char_t *)[string UTF8String], (int) [string length], YAML_PLAIN_SCALAR_STYLE);
is incorrect, we need to pass -1 as you said or [string lengthOfBytesUsingEncoding: NSUTF8StringEncoding] which may be bit faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants