<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&nbsp;completeFile = [112,&nbsp;114,&nbsp;105,&nbsp;110,&nbsp;116,&nbsp;40,&nbsp;34,&nbsp;104,&nbsp;101,&nbsp;108,&nbsp;108,&nbsp;111,&nbsp;32,&nbsp;119,&nbsp;111,&nbsp;114,&nbsp;108,&nbsp;100,&nbsp;34,&nbsp;41]<br class="">let&nbsp;str =&nbsp;String(validatingUTF8: completeFile)</blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><br class=""></blockquote>Did you see it? &nbsp;No?<div class=""><br class=""></div><div class="">What if our bytes are not UTF8? &nbsp;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*. &nbsp;</i>If they are not null-terminated,&nbsp;<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. &nbsp;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. &nbsp;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>