Variable Corrupted / Bloated - ios

I have an app and some users experience an error where it seems a variable gets corrupted, causing the app to crash. I am not sure what causes this corruption and have never been able to replicate the error on my test devices.
However today I got hold of a problem user's device and was able to perform po brokenvar in the console and got an output of the corrupted variable.
Here's the top 6 'lines' from the debugger:
The N‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂‚àö¬¥‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ć‚àö√°‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂¬¨¬•‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚àö¬∞‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö√ë‚Äö√тĆ‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ć‚àö√°‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àǬ¨¬®¬¨‚Ä¢‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö√ë‚Äö√тĆ‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ć‚àö√°‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö√ë‚Äö√тĆ‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂¬¨‚àû‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂‚àö¬¥‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ć‚àö√°‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√
And the bottom 6 'lines':
´¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ‚Äö√†√∂‚àö√∫‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚àö√´‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö√ë‚Äö√тĆ‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ć‚àö√°‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√Ñ√∂‚àö‚Ƭ¨¬•¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ‚Äö√†√∂‚àö√∫¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√Ü‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂‚àö‚à´¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ‚Äö√†√∂‚àö√∫¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú‚Äö√Ñ√∂‚àö√ë‚àö‚àÇ‚Äö√†√∂‚Äö√тĆ‚Äö√†√∂‚Äö√†√á‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂‚Äö√†¬¥¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ‚Äö√†√∂‚àö√∫¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√Ü‚Äö√Ñ√∂‚àö‚Ć‚àö‚àÇ‚Äö√†√∂‚àö‚à´¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ‚Äö√†√∂‚àö√∫¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®‚àö√ú¬¨¬®¬¨¬Æ¬¨¬®¬¨√ܬ¨¬®¬¨¬Æ¬¨¬®¬¨¬¢bel oven is marked but in good condition.
There is a lot of more gibberish in the middle - I copied and pasted the whole lot into TextEdit and it turned out being a ~170mb text file.
You can see the start The N and the end bel oven is.. which looks like the actual comment the user entered.
I did the po brokenvar output twice and compared the top/bottom 6 lines, they were exactly the same each time. This makes me think that it is a saving issue that has occurred once, and not something that is getting corrupted on the fly - though I may be way off..
The user would have entered plain text into a UITextField, which gets saved into a SQLite database. The crash occurs after reading the variable from the database, when I attempt to set the UITextField's text as the NSString.
The app is using a SQLite wrapper I found ages ago, lost the original link but found it here: https://github.com/ConnorD/simple-sqlite/blob/master/Sqlite.h
There doesn't seem to be any common thread with the handful of users who have experienced the problem. It might be the first time they use the app, or the hundredth.
I'm not sure why it is coming out corrupt/gibberish/garbled like this, or where to move on from here.
Any suggestions on how to proceed would be greatly appreciated.

Related

User Default Values Changing to Previous Values Seemingly Randomly - Swift

I am creating an app that is a game where there is a need to store the high score. I believe (correct me if I'm wrong on this, but this question made it seem this way) that user defaults are the best way to accomplish this.
Sometimes when I switch between views in my app, the values change to what they previously were. Then I will switch back to another screen, and they will go back to what they should be. This happens kind-of hit and miss, so it is hard to tell, but I think it happens most after it has been set multiple times since the app was last closed; though, I know at least sometimes it only happens after they have been set once.
I have used breakpoints to ensure that the values definitely are not being changed in the code. (I did this by putting a breakpoint where all of the user defaults are set and none of them went off even though the values changed)
The only code dealing with the user defaults is as follows:
UserDefaults.standard.set(newHighScore, forKey"highScore")
-> To set the User Defaults (where newHighScore is an integer)
let highScore = UserDefaults.standarard.value(forKey: "highScore")
-> To retrieve the values
UserDefaults.standard.synchronize()
-> Every time before and after I set or retrieve values (just to play it on the safe side and because it doesn't work so I'm overly cautious)
This question suggested restarting my mac (which I did) and then doing it only in the xcode simulator. I just did that and kept the breakpoints on all the times I set the values.
I have looked at these questions and this question seems similar, but the problem doesn't apply because it was decided that it would be fixed if the code wasn't running in a playground. My code is not running in a playground.
This question also seems similar, but it doesn't apply because the values are returning as null. Mine are just changing to a value they were previously. It is also written in objective-c, so I didn't completely understand what they did to fix it. I looked through the sources it recommended for help, but didn't see anything there that helped me either.
Thanks in advance for any help on what may be my problem. I haven't been able to find anything similar to make it seem like a bug in iOS 10 or Xcode 8 beta, but I am open to any suggestions to make my code work.

VerificationController abruptly stopped working for all apps

I'm using the VerificationController provided by Raywenderlich in several of my apps, and it's been fantastic. Totally reliable, easy to implement, and effective. It's been live in three of my apps for several months each.
However, two days ago, all three apps suddenly stopped working properly. Every purchase is now being flagged as invalid without exception, both for my live users and for my own test accounts. I've made no changes to the apps or their backends, in fact I've been moving apartments so I literally haven't touched them in a week or more. The change was instantaneous across all three apps, and I've understandably started getting complaints.
The problem seems to be in the checkReceiptSecurity() function (it's always returning NO when it needs to return YES for valid transactions), but the code inside that function is beyond my ability to comprehend. I'm hoping someone has encountered something like this, or perhaps is even experiencing it now, and knows a solution?
As far as I can tell, it seems to be happening on the second of these lines (VerificationController.m line 158).
require(signature_length > offsetof(struct signature_blob, certificate), outLabel);
require(signature_blob_ptr->version == 2, outLabel);
certificate_len = ntohl(signature_blob_ptr->cert_len);
Which are helpfully commented as "Make sure the signature blob is long enough to safely extract the version and cert_len fields, then perform a sanity check on the fields." When it hits the signature_blob_ptr line, it suddenly jumps to the end of the function, which I assume means that it failed a check having to do with the version number of some response from Apple?
Can anyone shed any light on what is happening? This is obviously devastating to my app portfolio, and I need to fix it immediately. I'll disable the verification temporarily and release an update if I have to, but I'd like to find a fix for whatever has changed...
Search for "receipt validation" at https://forums.developer.apple.com
Apparently, a certificate update just made VerificationController to stop working.
The obvious, but not quick at all, fix is to use the more recent receipt validation processing. See: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Introduction.html#//apple_ref/doc/uid/TP40010573-CH105-SW1
As for the code above, signature_blob_ptr->version == 3 now. But putting 3 instead of 2 in the code is not a fix as the signature is not 128 bytes long anymore.

CloudKit 'Unexpected Server Error' Anytime Manual Operations Performed in Dashboard

I have been developing an iOS app that utilizes the CloudKit feature available for Apple Developers. I've found it to be a wonderful resource, especially since the very day I started designing my backend, the service I was intending to use (Parse) announced it was shutting down. It's very appealing due to it's small learning curve, but I'm starting to notice some annoying little issues here and there so I'm seeking out some experts for advice and help. I posted another CloudKit question a couple days ago, which is still occurring: CloudKit Delete Self Option Not Working. But I want to limit this to a different issue that may be related.
Problem ~ Ever since I started using CloudKit I have noticed that whenever I manually try to edit (delete an entry, remove or add part of a list, even add a DeleteSelf option to a CKReference after creation), and then try to save the change, I get an error message and cannot proceed. Here is a screenshot of the error window that appears:
It's frustrating because anytime I want to manipulate a record to perform some sort of test, I either have to go do it through my app, or just delete the record entirely and create a new one (that I am able to do without issue). I have been just working around this issue for over a month now because it wasn't fatal to my progress. However, I am starting to think that this could be related to my other CloudKit issues, and maybe if I could get some advice on how to fix it I could also solve my other problems. I have file numerous bug reports with Apple, but haven't received a response or seen any changes.
I'd also like to mention that for a very long time now (at least a few days), I've noticed down in the bottom left hand corner of my Dashboard that it is consistently saying that it's "Reindexing Development Data". I remember at first that wasn't an issue, I would get that notification after making a change but it'd go away after the operation is complete. Now it seems to be stuck somewhere inside the process. And this is a chronic issue, it's saying this all the time, even right when I log into my dashboard.
Here is what I'm talking about:
As time goes on I find more small issues with CloudKit, I'm concerned that once I go into production more problems could start manifesting and then I could have a serious issue. I'd love to stick with CloudKit and avoid the learning curve of a different service like Amazon Web Services, but I also don't want to set myself up for failure.
Can anyone help me with this issue, or has anyone else experienced it on a regular basis? Thanks for the advice and help!
Pierce,
I found myself in a similar situation; the issue seemed to be linked to Assets; I had an Asset in my record definition. I and several other I noted reported the re-indexing issue on the apple support website and after about a month it eventually disappeared.
Have you tried resting your database schema completely, snapshot the definition; since you zap it completely and than reset, see inset.
Ultimately I simply created a new project, linked it to cloud kit and use the new container in my original app.

How to debug syscall_thread_switch in iOS 8.3?

Since moving to iOS 8.3, I'm encountering this error where the main thread will get stuck in this call. A few other threads are also stuck in that call. There is none of my code in any thread that leads to this call, so I'm stumped as to why this is happening. It happens randomly, sometimes, when tapping a button bar item, sometimes while redrawing charts (using ShinobiCharts), etc.
Here is the stack trace from Xcode:
Anybody has any clue as to why this is happening and how to fix it? It's very annoying because when I get stuck there, I have to relaunch the app. Note that this is happening in the simulator so far. I'm in the early stage of developing this app and spend most of my time in the simulator. I haven't seen the error happening yet on a real device but, again, I haven't run the app that often on the device.
Knock on wood, but I think I figured it out (at least in my instance).
What led to the solution was a search for syscall_thread_switch, which led me to this answer here:
https://stackoverflow.com/a/30333203/978509
Which, if you look at the backtrace I linked (https://gist.github.com/Shalmezad/65ff89d20aa7e0a9d094), every syscall_thread_switch is preceded by OSSpinLockLockSlow, which the answer notes looks like Livelock, but due to the low CPU usage, is more evident of a deadlock.
Going through my code, I found that for every background task, I created a new dispatch_queue_t each time. I since redid how that works to use the same queue, which seems to have fixed the issue.
Without further information from nemesis (mainly some code snippets showing how he's setting up background tasks), I cannot answer their specific question, however this should point people in the right direction for fixing the issue.

Delphi 5 application partially loaded in task manager, takes forever to actually display

I have an application written in Delphi 5, which runs fine on most (windows) computers.
However, occasionally the program begins to load (you can see it in task manager, uses about 2.5-3 MB of memory), but then stalls for a number of minutes, sometimes hours.
If you leave it long enough, the formshow event will eventually occur and the application window will pop up, but it seems like some other application or windows setting is preventing it from initially using all the memory it needs to run (approx. 35-40 MB).
Also, on some of my client's workstations, if they have MS Outlook running, they can close it and my application will pop up. Does anyone know what is going on here, and/or how to fix it?
Since nobody has given a better answer I'll take a stab at how to solve this:
There's something in your initialization that is locking it up somehow. Without seeing your code I do not know what it is so I'll only address how to go about finding it:
You need to log what you accomplish during startup. If you have any kind of screen showing I find the window title useful for this but it sounds like you don't--that means you need to write the log to a file. Let it get lost, kill the task and see where it got.
Note that this means you need to cleanly write your data despite an abnormal program termination. How to go about this:
A) Append, write your line, close.
B) Write your line, then flush the file handle.
C) Initially write your file to consist of a large number of blanks--ensure this is larger than the actual log will be. Write your line. In case of abnormal termination it will retain the original larger file size.
I would write a timestamp on every log item so you can see if it's just processing something too slowly.
If examining the log shows you where the problem is, fine. If, as usually happens, it's not enough you put a bunch more logging between the last item that did get logged and the next one that didn't--I've been known to log every line when hunting a cryptic problem that only happened on someone else's system.
If finding the line isn't enough to pinpoint the problem also dump the value of relevant variables.
Finally, if such intense scrutiny makes the bug go away start looking for an uninitialized variable. (While a memory stomp is also an option I doubt it's the culprit here.)

Resources