Critical bug in Core Data

Talk to other Pedia users about the programs, share tricks and tips or ask questions about existing features.
Post Reply
Black Smurf
Addicted to Bruji
Addicted to Bruji
Posts: 30
Joined: Mon Mar 26, 2007 11:15 am
Location: Germany

Critical bug in Core Data

Post by Black Smurf »

The German news site mactechnews.de just reported a critical error in Apples core data implementation in Leopard (sorry, the text is in German):

Anscheinend hat Apple einen schweren Fehler in Mac OS X 10.5 Leopard übersehen. In Anwendungen, die Apples Core Data benutzen, kann es sehr leicht zu einem kompletten Datenverlust kommen. Setzt eine Anwendung Apples Core Data mit einer Binary Storage oder eine XML Storage ein, kommt es durch doppeltes Sichern (im Ablage-Menu oder mit Befehlstaste+S) ohne zwischendurch eine Änderung gemacht zu haben zu einem kompletten Datenverlust.
Sollten Sie Anwendungen mit Core Data unter Leopard nutzen, machen Sie häufig Backups und fragen Sie bei den Entwicklern nach, ob die Programme von diesem Problem betroffen sind.
Der Fehler fiel der MacTechNews.de-Redaktion heute nach der Veröffentlichung von MacStammbaum 5 auf. Die Datenbank von MacStammbaum 5 nutzt ebenfalls Core Data, und nachdem sich ein Kunde mit diesem obskuren, zuerst nicht reproduzierbaren Problem meldete, stießen wir dann doch recht bald auf die Ursache. Glücklicherweise konnten wir schnell ein Update über die automatische Aktualisierung bereit stellen, um das Problem zu beheben.
Gerne leisten wir betroffenen Entwicklern mit Core Data-Anwendungen Hilfe bei der Implementierung eines Workarounds.
The translation of the essential sentence is roughly: "If an application uses Apples Core Data with a binary storage or a XML storage, saving two times in a row (via menu or Command+S) without making any changes in between leads to a complete data loss". :shock:

Are the -Pedias affected by this? (The do use core data, do they?)
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

Thank you for letting us know. They picked up those news from Simon Fell who reported that bug on the Cocoa mailing list (I can't find that post in the regular Apple archives); it's good to know the German sites are paying attention. Being a subscriber to the list and and because the Pedias use Core Data I did read that post. The good news is that we don't use Binary or XML but SQL. On top of that the Pedias won't save if there are no changes, they first check that there is something to save, this is what our code looks like:

Code: Select all

if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error])
The bug appears when you save and there are no changes to save. So even if we did use the XML or Binary store we wouldn't hit that bug. I believe this is the reason that bug went undetected by Apple or others and made it into Leopard as I think a lot of developers use the convention above of checking before saving as it comes directly from Apple's sample code. I expect it to be fixed with 10.5.1 but in the meantime sleep soundly that your collection information is safe with the Pedias. Although that is no excuse not to backup, so go make a copy of your data folder now. :) (Maybe they put this bug in so they could test Time Machine).
Post Reply