TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

iOS 12 Safari Array reverse bug

333 pointsby wonderfulyover 6 years ago

19 comments

pjc50over 6 years ago
Finally we've discovered why people are asked in interviews to reverse an array.
ArmandGrilletover 6 years ago
I can also see the bug on macOS with Safari 12.0.<p>I find it quite worrying that devs already wrote a lib to fix the issue but didn&#x27;t fill a bug report to Apple and shared it on SO. Anyway, a trendy HN post might be enough to get the attention of some Apple devs and I&#x27;ve pinged a dev just in case: <a href="https:&#x2F;&#x2F;twitter.com&#x2F;ArmandGrillet&#x2F;status&#x2F;1042339847384518656" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;ArmandGrillet&#x2F;status&#x2F;1042339847384518656</a>
评论 #18023722 未加载
评论 #18024803 未加载
评论 #18026288 未加载
评论 #18023383 未加载
评论 #18024695 未加载
评论 #18023117 未加载
评论 #18023368 未加载
评论 #18023533 未加载
评论 #18023069 未加载
评论 #18024028 未加载
评论 #18025175 未加载
评论 #18025041 未加载
评论 #18022899 未加载
peterkellyover 6 years ago
And now we&#x27;ll have array-reverse-polyfill showing up as a 6th-level npm dependency on our projects for years to come.
评论 #18024474 未加载
smailiover 6 years ago
It appears this was already reported and fixed in WebKit - <a href="https:&#x2F;&#x2F;bugs.webkit.org&#x2F;show_bug.cgi?id=188794" rel="nofollow">https:&#x2F;&#x2F;bugs.webkit.org&#x2F;show_bug.cgi?id=188794</a> but not specifically for the Safari browser.
评论 #18023552 未加载
评论 #18023985 未加载
dan-robertsonover 6 years ago
This bug is very much like the most common mistake I see on Common Lisp stack overflow where one tries to mutate constant (quoted) data.<p>However JavaScript has no similar notion of constant data but implementations try to infer it as an optimisation. In this case that inference was wrong.<p>I think the memory structure looks something like:<p><pre><code> arr -&gt; box1 -&gt; 1,2,3,4 </code></pre> Reversing:<p><pre><code> arr -&gt; box1 -&gt; 4,3,2,1 </code></pre> But the data occupying the same region of memory before and after the sort. So then when the page is refreshed the JavaScript doesn’t change and the literal data must be included in the “parsed&#x2F;compiled” form that is reused and so it is initialised as<p><pre><code> arr -&gt; box2 -&gt; 4,3,2,1 </code></pre> The correct behaviour should be as follows:<p><pre><code> 1. arr -&gt; box1 -&gt; loc1: 1,2,3,4 2. Reverse 3. arr -&gt; box1 -&gt; loc2: 4,3,2,1 4. Refresh 5. arr -&gt; box2 -&gt; loc1: 1,2,3,4 </code></pre> The “box” corresponds to the JavaScript object for the array (so mutating the array data can change the box, the data it points at, but not just the reference “arr” as the object might be pointed to from elsewhere). And this box has another pointer to the data for the array (and presumably some bit flag to say whether that is copy-on-write or not). This allows for more efficient array functions when the data doesn’t actually change
0x0over 6 years ago
The weirdest thing about this is the fact that the bug occurs after a page reload. Does safari cache jit code and the javascript heap&#x2F;objects between pageloads?
评论 #18025297 未加载
评论 #18023184 未加载
评论 #18023098 未加载
kbumsikover 6 years ago
I think Apple has to consider separating Safari (and other bundled apps) from the iOS release so that users can update a quick fix through the App Store without waiting for a new iOS update.<p>There was a serious WebAssembly regression in iOS 11.2 that makes wasm effectively useless [1]. Devs had to disable wasm and wait for <i>months</i> until iOS 11.3 is released.<p>Apple never releases a iOS hot fix just for a single Safari bug. Then why Apple don&#x27;t let users to update Safari separately?<p>[1]: <a href="https:&#x2F;&#x2F;bugs.webkit.org&#x2F;show_bug.cgi?id=181781" rel="nofollow">https:&#x2F;&#x2F;bugs.webkit.org&#x2F;show_bug.cgi?id=181781</a>
评论 #18028414 未加载
0x0over 6 years ago
Bug does not trigger on &quot;Safari Technology Preview Release 65 (Safari 12.1, WebKit 13607.1.5.2)&quot; on macOS 10.13.6. Fixed already, or not yet introduced?
评论 #18023231 未加载
kuonover 6 years ago
This sounds like a very bad bug, I wonder how bad it is &quot;in the wild&quot;.
评论 #18022965 未加载
fuzzy2over 6 years ago
I wonder if `splice`, `shift`, `unshift` and other methods that modify arrays in-place are also affected.
评论 #18023648 未加载
dkmarover 6 years ago
Woah. I think I ran into this last night after updating to Safari 12 on macOS. I was typing my message into messenger.com (facebook messenger), and all of my typing was reversed. I even took a photo of it
评论 #18028228 未加载
chearonover 6 years ago
I&#x27;m not seeing Safari 12 in the App Store (macOS 10.13.6). I wonder if they pulled the update because of this? I have Safari 11 still but my colleague got Safari 12 through the App Store.
评论 #18025369 未加载
toxikover 6 years ago
Isn&#x27;t this part of the faster loading that some Web browsers do? Essentially the idea is that the browser muddies the idea of a closed page in favour of being able to restore it faster.
评论 #18023686 未加载
评论 #18025353 未加载
cryptonectorover 6 years ago
Should we hold off on updating then?
matkinzover 6 years ago
&gt;I wrote a lib to fix the bug. <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;array-reverse-polyfill" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;array-reverse-polyfill</a><p>everyday we stray further from god
评论 #18023419 未加载
评论 #18024950 未加载
评论 #18022941 未加载
sitepodmattover 6 years ago
Fixed. Scheduled. Coming to iOS 15 in 2022...
评论 #18025714 未加载
symlinkkover 6 years ago
Does Apple not believe in unit tests or something? This and the password login bug from a few months ago make me pretty concerned.
评论 #18025347 未加载
vishalsharmaover 6 years ago
Now they will release iOS 13 for this :)<p>P.S. <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=uG8bNDw6Ftc" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=uG8bNDw6Ftc</a>
maxwellitoover 6 years ago
Ironically, I got an ad banner for Apple at the top of this page. Saying &quot;Engineer in Europe. Innovate at Apple.&quot;<p>However, this bug sounds pretty serious! :-S