-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crashing in [RLMMigration verifyPrimaryKeyUniqueness] #1620
Comments
Do you have strings with 10KB+ common prefixes? The depth of the recursion in |
Hmm, nope. The primary key is a string URL, and I don't see any abnormally long ones. The only weirdness is that a handful of rows seem to have an empty string URL. It is possible that I managed to insert rows with empty primary keys, but it seems unlikely. Here is the actual DB: https://dl.dropboxusercontent.com/u/20329687/RealmMigrationCrash.zip Has it been corrupted somehow? |
Incidentally, the older Realm browser also crashes when I try to change the contents of the empty string rows. http://pastebin.com/6y5SQUmf |
It appears that the rows that are showing up in the browser as having empty URLs have embedded NUL bytes, which is something our string indexing code currently breaks on (and apparently the browser has issues with too). If this is actually the problem, then the simplest workaround while we work on fixing the problem would be to enumerate the objects in your migration block and delete the ones which have invalid URLs. |
Thanks. I tried deleting and setting a new value in the migration, but both crash. [migration enumerateObjects:OOURLCacheRecord.className block:^(RLMObject *oldObject, RLMObject *newObject) { index_string.cpp:551: [realm-core-0.88.5] Assertion failed: pos != values.size() [migration enumerateObjects:OOURLCacheRecord.className block:^(RLMObject *oldObject, RLMObject *newObject) { index_string.cpp:551: [realm-core-0.88.5] Assertion failed: pos != values.size() My app is still alpha so I don't care much about migrating existing users. Any tips on how to prevent this from happening to begin with? Can you give me an example of a URL with null bytes? As far as I can tell my code will not let anything other than valid NSURL objects into the database, which makes me think this is memory or file corruption. |
What you're checking for in your code isn't for null bytes, but rather if the string is null. ( Here's one way to check if an NSString contains a null bytes: NSString *url = @"myurl";
NSData *data = [url dataUsingEncoding:NSUTF8StringEncoding];
UInt8 asciiNull[] = { 0x0 };
NSData *zeroData = [NSData dataWithBytes:asciiNull
length:sizeof(asciiNull)];
NSRange range = [data rangeOfData:zeroData
options:kNilOptions
range:NSMakeRange(0u, [data length])];
if (range.location != NSNotFound) {
NSLog(@"Not safe to add this to a Realm: %@", url);
} |
Hi Matt. Sorry you are running into issues. I can easily reproduce the crashes you mention using your database. There are some entries containing embedded nulls in your db, but any attempt to delete or change these entries cases a crash as you described. Looking the offending urls, each string seems to be 100k+ bytes of garbage data. It isn't clear if this is the data being inserted or if the db is being corrupted. We already have someone working on a proper fix for the indexing issues which we believe is the root cause of your problems, but there is not currently an eta for a fix. In the meantime we will probably release a workaround which no longer automatically creates indexes for primary key properties. I made a pr for this here #1623 if you want to try it out. This wont fix existing databases but new databases/installs will no longer use an index by default which should hopefully avoid the issue for the time being. |
Hi Ari, np, I'm enjoying Realm so far. NSURL returns nil if you init with a string containing nulls, but it is possible that I had/have a heap corrupting bug. Will see if it happens again. FWIW as a user I'd expect primary keys to be automatically indexed. I'd like to be able to catch an exception to detect a corrupt db, delete, then create a new one, but for now I'll just check for successive crashes. Maybe worth fuzz testing the way SQLite does? |
Closing this as this should no longer happen with new databases. |
Hiya. I'm hitting a crash during migration with Realm 0.91.1.
Looks like a stack overflow in
tightdb::StringIndex::distinct
called from[RLMMigration verifyPrimaryKeyUniqueness]
Full stack: http://pastebin.com/fVPHKskX
At the moment this is only happening on device (iPhone 6, iOS 8.2) with a database containing several thousand items. This is a debug build with malloc scribbling enabled, and it crashes reliably on start every time. I believe it is migrating from a database created using Realm 0.86.
I'll try to find other ways to repro, and share if possible.
The text was updated successfully, but these errors were encountered: