Skip to content

Encounter an occasional NSRangeException crash #67

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

Closed
xuzhongping opened this issue Sep 5, 2022 · 2 comments · Fixed by #68
Closed

Encounter an occasional NSRangeException crash #67

xuzhongping opened this issue Sep 5, 2022 · 2 comments · Fixed by #68
Labels
bug Something isn't working incremental incremental decoding

Comments

@xuzhongping
Copy link

Hi, I have an occasional out-of-bounds crash, but I can't give the necessary steps, the scene that comes up has tons of webp animations playing, and I can provide the stack:

#0 Thread

NSRangeException

*** -[__NSFrozenArrayM objectAtIndexedSubscript:]: index 66 beyond bounds for empty array

CoreFoundation
___exceptionPreprocess + 216
3
CoreFoundation
-[__NSFrozenArrayM objectAtIndexedSubscript:] + 120
4
MyAPP
-[SDImageWebPCoder animatedImageDurationAtIndex:] (SDImageWebPCoder.m:0)
5
MyAPP
-[SDAnimatedImage animatedImageDurationAtIndex:] (SDAnimatedImage.m:0)
6
MyAPP
-[SDAnimatedImagePlayer displayDidRefresh:] (SDAnimatedImagePlayer.m:296)
7
MyAPP
-[SDDisplayLink displayLinkDidRefresh:] (SDDisplayLink.m:205)

In addition, I see this code, is there a potential thread insecurity here?

- (NSTimeInterval)animatedImageDurationAtIndex:(NSUInteger)index {
    if (index >= _frameCount) {
        return 0;
    }
    if (_frameCount <= 1) {
        return 0;
    }
    return _frames[index].duration;
}
@dreampiggy
Copy link
Contributor

dreampiggy commented Sep 5, 2022

Maybe. But for most cases, the static animated coder could not change the image data and frame count. So the _frameCount and _frames, is actually readonly because it only initialize once in the objc init method. (Check code there)

Only those incremental decoding, which may update the _frameCount variable (The network new bytes available, so the decoder may find more frames count available), has potential thread-safe issue and need to be guarded by lock or some atomic logic.

@dreampiggy
Copy link
Contributor

@xuzhongping I believe this PR can fix the issue. Which does not effect the normal animation decoding speed.

I'll release a new patch version for SDWebImageWebPCoder, please have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working incremental incremental decoding
Projects
None yet
2 participants