Memcpy crash in createFromCharPointer

Hi,

juce::StringArray::fromTokens crashes in line 151 memcpy (dest.getAddress(), start, numBytes); in createFromCharPointer in juce_String.cpp.

See code below:

std::vector<char> bytes;

bytes.push_back(-56);
bytes.push_back(51);
bytes.push_back(-31);
bytes.push_back(1);
bytes.push_back(-84);
bytes.push_back(4);
bytes.push_back(0);

jassert(juce::CharPointer_UTF8::isValidString(bytes.data(), (int) bytes.size())); // OK

auto s = juce::String::createStringFromData(bytes.data(), (int) bytes.size());

auto array = juce::StringArray::fromTokens(s, ",", ""); // <---- crash

Please can this be fixed?

Best,

Jelle

Thanks for reporting, and especially for including code to repro the issue.

We’ve made two changes in this area to address this crash.

The first problem was that isValidString was returning a false positive result for the string in your example. The provided string is not valid UTF-8, and the result of isValidString will now reflect that.

Secondly, ideally we wouldn’t crash, even when attempting to tokenise an invalid UTF-8 string. CharPointer_UTF8 will now return a substitute codepoint in the case that reading a codepoint from the bytestream fails.

1 Like