<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class="">let completeFile = [112, 114, 105, 110, 116, 40, 34, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 34, 41]<br class="">let str = String(validatingUTF8: completeFile)</blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><br class=""></blockquote>Did you see it? No?<div class=""><br class=""></div><div class="">What if our bytes are not UTF8? Well, one would hope that the constructor, um, validates them.</div><div class=""><br class=""></div><div class="">Turns out it does validate them, *<i class="">but only if the bytes are null-terminated*. </i>If they are not null-terminated, <a href="https://github.com/apple/swift/blob/510f29abf77e202780c11d5f6c7449313c819030/stdlib/public/core/CString.swift#L41" class="">we get UB</a>.</div><div class=""><br class=""></div><div class="">IMO:</div><div class=""><br class=""></div><div class="">1. If this constructor insists on null-terminated bytes, it should say so in the name (e.g. validatingNullTerminatedUTF8:), and it should crash deterministically if it gets non-terminated bytes, or</div><div class="">2. It should not require null-terminated bytes</div><div class=""><br class=""></div><div class="">Drew</div><div class=""><br class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""></div></div></div></body></html>