Re: AVMetadataItem key
Re: AVMetadataItem key
- Subject: Re: AVMetadataItem key
- From: Fritz Anderson <email@hidden>
- Date: Mon, 05 Oct 2015 16:41:12 -0500
This is embarrassing…
On 4 Oct 2015, at 5:39 PM, Fritz Anderson <email@hidden> wrote:
>
> func OSTypeFor(code: UInt32,
> encoding: UInt = NSMacOSRomanStringEncoding)
> throws -> String
> {
> let codePtr = UnsafeMutablePointer<UInt32>.alloc(1)
> codePtr.initializeFrom([code])
> defer { codePtr.destroy() }
>
> let fourChars = UnsafeMutablePointer<CChar>(codePtr)
/*** OOPS ***/
> if let retval = String(CString: fourChars,
> encoding: encoding)
> {
> return retval
> }
> else { throw OSTypeError.BadStringFormat }
> }
>
fourChars gets passed to String(CString:encoding:) without a fifth character to provide the NUL to terminate the C String. I’m surprised it was well-behaved in my playground, but something _will_ go wrong in the mean time. fourChars should be an unsafe buffer of five or six CChar, with [4] zeroed-out.
Maybe I was rescued by the page being larger than four bytes and zeroed-out, but an aggressive address sanitizer would cry foul.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden