8 ms·
What I'm really curious about is how bugs/errors in the iOS typesetting algorithm result in a crash, rather than just wrong or nonsense typesetting -- and how t
by jrochkind1 9y ago
What I'm really curious about is how bugs/errors in the iOS typesetting algorithm result in a crash, rather than just wrong or nonsense typesetting -- and how the last time this happened, they appearently just fixed the specific case, but not the ability of bugs/errors in the typesetting algorithm to crash the system.
I am not surprised there will be errors/bugs in the typesetting algorithm, as the OP demonstrates, this stuff is extraordinarily complicated to do for every language/all of unicode. But if you have something so complicated that bugs/errors aren't surprising -- you'd think you'd want to make sure they didn't cause hard crashes.
- stcredzero 9y agoyou'd think you'd want to make sure they didn't cause hard crashes. Any Apple people want to chime in? Why wasn't the general bug -- where there could be even the possibility of a "text crash" -- fixed?
- glibgil 9y agoIf Apple people chime in I think they get beheaded. It never happens
- saagarjha 9y agoThey do sometimes, but generally not for topics such as these.
- acheron 9y ago“The bomb says no, Brian.” https://www.penny-arcade.com/comic/2007/05/23/ https://www.penny-arcade.com/comic/2007/05/23/
- AceJohnny2 9y agoAbsolutely. It's drilled and repeated on a regular schedule: Shut the fuck up.
- ghusbands 9y agoYou realize that there's no such thing as "don't ever crash" fix, right? Maybe they added some defensive code and maybe they didn't, but if they're using an unsafe language, there's always the possibility of more such issues.
- stcredzero 9y agoYou realize that there's no such thing as "don't ever crash" fix, right? You answered universally for all contexts, ever, everywhere. That's a usually quite a foolish thing to do. In ObjectStudio Smalltalk, there was actually a place where you could define an empty lambda as the "top-level" exception handler. Once you did that, all Smalltalk exceptions did nothing. There you go: a "don't ever crash" fix, in a language many would call "unsafe." You are now technically wrong, which is the best kind! Exceptions can be caught in C++, Objective-C, and in Swift. You can even do this for C. There is apparently a history of similar bugs where certain data crash processes in iOS. Depending on how you count, this is either #3 (strings) or #5. https://www.theverge.com/2018/2/15/17015654/apple-iphone-crash-ios-11-bug-imessage https://www.theverge.com/2018/2/15/17015654/apple-iphone-cra... Given that, why wouldn't Apple take steps to make sure that certain critical processes are architecturally immune to this sort of thing? Springboard going away is pretty horrendous. Messages app, given that it's a core functionality for a phone, is almost as bad. if they're using an unsafe language, there's always the possibility of more such issues. There are software projects where certain things simply can't be allowed to happen, ever. Apparently, Apple isn't operating at that level.
- annabellish 9y agoYikes. Instead of having heap corruption which immediately causes a hard failure, you want heap corruption which is silently ignored and (?????) happens on a device in which people access banking and all their personal identity stuff?
- stcredzero 9y agoNo. But the heap corruption shouldn't make certain facilities go away, or hang around looking broken. For example, Springboard could be separated into separate processes (display and monitor) and built on some kind of event queue. Then, if an event containing some kind of poison pill brought down the display, the monitor could note the crash and after a few retries, evict the poison pill event and bring the display back up without it. It's the not even 2nd rater who gives up on something which causes such a huge hole in the user experience, saying to themselves, "Uhhhh, there's no such thing as a never crash fix." You're not a 1st rate programmer if you only think one step ahead and say, "Uhhh, you can't guarantee no crashes," then leave such a huge hole in your system. The 1st rater engages in a bit of lateral thinking. The real problem isn't to eliminate crashes. The real problem is to eliminate the hole in the UX! Anything you can detect, you can "fix," and sometimes a guaranteed "fix" every bit as good or better. (It's exactly this kind of mediocre thinking that led to the hardware quality doldrums in the 90's. The OS crashed so often, hardware manufacturers started to make cheap machines that could only stay up for a few days anyways.)
- blackflame7000 9y agoI bet you a dollar its related to Auto-Correct trying to interpret some malformed word.
- arbie 9y agoWhy would Auto-Correct kick in on incoming texts or on browser pages?
- blackflame7000 9y agoI read that it was related to text-boxes so I figured that could be a potentially hidden culprit. I haven't heard of web pages crashing due to embedded text but if so then I retract my hypothesis. 2nd Sentence of the article says text box but not sure what "other places" are: "Basically, if you put this string in any system text box (and other places), it crashes that process."
- ghusbands 9y agoFrom the article's source article: "iMessages, [...] Facebook Messenger, WhatsApp, Gmail, and Outlook for iOS [...] can become disabled once a message is received". "It might be difficult to fix and delete the problem message". From the article: "I’ve been testing it by copy-pasting characters into Spotlight so I don’t end up crashing my browser". "I can cause this crash to happen more reliably in browsers by clicking on the string". So, not text-box specific and happening on display for a wide variety of applications, including web pages.
- pkaler 9y agoThe crash seems to be in CoreText. CoreText is embedded/linked in Messages, Spotlight, Springboard, etc. CoreText is written in C. The fix would be to rewrite CoreText in a memory safe language like Swift. This would be “hard”. Or put CoreText in an XPC container. This would both be “hard” and result in terrible performance. For more details on how hard C, memory management, systems programming, and operating system development is please refer to your local copy of Modern Operating Systems by Andy Tannenbaum.
- mapmap 9y agoI'm guessing C is how they get the performance they need. Re-writing in Obj-C or Swift would likely have speed tradeoffs.
- ams6110 9y agoObj-C is C, or more accurately a superset of it.
- justAnotherNET 9y agoSure, but would it crash the entire OS when there’s a problem?
- pjmlp 9y agoC code only got fast thanks to 40 years of optimizer improvements, taking advantage of UB.
- zxxon 9y agoHuh? C is fast (compared to Swift) because using it doesn't imply sprinkling lots of sugar (like ARC) into the resulting machine code. Simpler languages like Fortran can turn into even faster code than a C implementation. UB optimizations aren't that relevant for real-world performance.
- pjmlp 9y agoCode generated by C compilers is fast in 2018. Code generated by C compilers for C64, Spectrum, Atari, Atari ST, Amiga, Mac, CP/M, MS-DOS, Windows 3.x, Nintendo, MegaDrive,... systems meant many times the code would be 80% like this: void some_func(/* params */) { asm { /* actual "C" code as inline Assembly */ } } Lots of Swift sugar also gets optimized away, and there is plenty of room to improvement. The code that current C compilers don't generate, many times is related to taking advantage of UB. They also generate extra code for handling stuff like floating point emulation though. Just as an example, IBM did their whole RISC research using PL/8, including an OS and optimizing compiler using an architecture similar to what LLVM uses. They only bothered with C, after making the business case that RISC would be a good platform for UNIX workstations.
- evmar 9y agoI wrote some similar bugs to this in the complex text handling in Chrome. In text layout you do a lot of indexing into various arrays -- like the array of code units of the input string, or an array of metadata collected per-code point, or an array of data collected per-grapheme. Oftentimes those arrays are all the same length (like in simple text like Chinese) and mixing up which index to use where is no problem. And then when it goes wrong you're violating array bounds which is a crashable offense. I agree that it's stupid to have code that causes crashes here. My only defense is that I had a lot of other work to do and complex test pathological cases only affect a fraction of users, none of whom were the ones yelling at me about other bugs. I am rooting for Servo, where they are using a language that defends against bad programmers like me. PS: If a web page wants to crash, it easily do so by allocating memory in a loop, so making web pages that crash isn't as exciting as it is in Core Text in general. Of course crashes can often be escalated into RCE, but the Chrome sandbox was there to mitigate that.
- gok 9y agoHow would using Rust help this case? An out of bounds array would still lead to a crash, and thus a DoS in the crashing application. You could sandbox the text rendering into its own process to solve that, but then you could do that using unsafe languages anyway.
- tomjakubowski 9y agoRust would significantly help to prevent the escalation of this crash into an RCE.
- GirlsCanCode 9y agoThe Rust zealots are awake!
- mrob 9y agoFully sandboxing an unsafe renderer might have unacceptable performance. E.g. you'd have to reset the internal state after every call, otherwise invalid text on a phishing website might be able to subvert the renderer to make it render text in the URL bar to read something different.
- rlanday 9y agoWhy does any bug result in a crash rather than just random unexpected behavior? There's a limit to how much it's practical to isolate things. For example, Chrome uses different processes to render different web pages, so a crash in one renderer shouldn't affect the others, but it doesn't parse HTML in one process, compute layout in another, execute JavaScript in another, and so on.
- crumbshot 9y agoSomeone posted a crash report: https://gist.github.com/steipete/a759b56dc1b5d94ba5b3c03ddd00a1ed https://gist.github.com/steipete/a759b56dc1b5d94ba5b3c03ddd0... Looks like a heap corruption, leading to a failure when allocating memory later on: Application Specific Information: abort() called *** error for object 0x604000673e00: Invalid pointer dequeued from free list Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x00007fff73a30e3e __pthread_kill + 10 1 libsystem_pthread.dylib 0x00007fff73b6f150 pthread_kill + 333 2 libsystem_c.dylib 0x00007fff7398d312 abort + 127 3 libsystem_malloc.dylib 0x00007fff73a9bdbf nanozone_error + 502 4 libsystem_malloc.dylib 0x00007fff73a8fdac _nano_malloc_check_clear + 410 5 libsystem_malloc.dylib 0x00007fff73a901d7 nano_calloc + 72 6 libsystem_malloc.dylib 0x00007fff73a8acc0 malloc_zone_calloc + 87 7 libsystem_malloc.dylib 0x00007fff73a8b5d6 calloc + 30 Probably caused by an out of bounds write on some heap buffer. If this bug is also present on OS X, it would be interesting to see where it crashes with some of the malloc debugging flags enabled (https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html https://developer.apple.com/library/content/documentation/Pe...), hopefully to get a crash a bit closer to the root cause.
- vxNsr 9y agoThis char string will crash safari on my up to date Mac.
- crumbshot 9y agoCould you run Safari under lldb, setting environment variable DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib? Should look something like this: $ lldb /Applications/Safari.app/Contents/MacOS/Safari (lldb) env DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib (lldb) process launch Assuming this is a heap buffer overflow, this should cause it to crash at the point of memory corruption, as it hits an adjacent guard page.
- userbinator 9y agothis stuff is extraordinarily complicated to do for every language/all of unicode. Perhaps this sounds a bit Anglocentric, but isn't it unfortunate that this string crashes the devices even of those people who have never heard of and likely won't ever need to use the language it's written in? The majority of people use a tiny fraction of Unicode --- the parts that cover the languages they use; everything else is useless to them --- or in cases like this, even a liability. It would greatly reduce the number of affected devices, especially with bugs like this having possible security implications, if the text rendering system were more modular and perhaps divided into separate optional components: Latin (maybe not optional), CJK, and other complex scripts. I know Windows has/had a similar feature: https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/nishants/WindowsLiveWriter/HowtosetupvariationsinMOSS2007_12169/clip_image002_2.jpg https://msdnshared.blob.core.windows.net/media/TNBlogsFS/Blo... This way, those who have no need for anything other than Latin scripts get the simple and hopefully much less buggy rendering algorithm, while those who do need the others can do so without unnecessarily burdening everyone else.
- Manishearth 9y agoUh, no, Windows doesn't have a similar feature. That Windows option is specifically for: - linebreaking support for east and southeast asian languages: Many of them don't use spaces, so if you want to know where you can break lines it is best to know what the words are. For this you need to have a pretty large dictionary file stored. - fonts - probably various assets for RTL languages (changed backgrounds, changed layout files, etc) This is Windows providing this option for a very specific thing (and also downloading some files), for which there is okayish fallback functionality. Not cfg'ing the entire text stack. I don't think you can easily slice and dice a text stack so that you can only pull in the components needed for Latin scripts without making it even more prone to bugs. You could write entirely separate stacks specialized for each group of scripts. But you'd probably end up with one for Latin/Cyrillic/Greek, one for Chinese/Japanese (not Korean) and one for "all the rest". There's enough feature overlap between most of the complex languages that there's questionable benefit to separating that out. For example, most of the underlying text functionality in Telugu or other Indic scripts is not overall different from things in Hangul or Arabic (Arabic is more complex, actually), it's just that Telugu has certain features that press the buttons in just the right way to cause this crash. Which means that if you want to prevent this crash for other language users, what you need to do is not attempt to render Telugu, not swap out the font stack. Like, looking at the last iOS crash that happened -- with the Arabic text -- that was because chopping off the end of a string of Arabic text doesn't guarantee that the string will be shorter. Really, you can replicate this for most scripts, it's just subtler (Even English has support for this, if your kerning is extreme enough. As long as your stack supports kerning, it supports everything necessary to crash this bug). So, the root text stack functionality that lets this happen is necessary for all scripts, Arabic just ends up pushing the right buttons in the right order to cause a crash.