• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AVMetadataItem key
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >AVMetadataItem key (From: "Jan E. Schotsman" <email@hidden>)
 >Re: AVMetadataItem key (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: Value of type '[AnyObject]!' has no member 'Generator'
  • Next by Date: Re: Value of type '[AnyObject]!' has no member 'Generator'
  • Previous by thread: Re: AVMetadataItem key
  • Next by thread: Re: AVMetadataItem key
  • Index(es):
    • Date
    • Thread