Peter-Schorn / SpotifyAPI

A Swift library for the Spotify web API. Supports all endpoints.
https://peter-schorn.github.io/SpotifyAPI/documentation/spotifywebapi
MIT License
269 stars 33 forks source link

"extendPagesConcurrently" causes crash #60

Closed wiencheck closed 6 months ago

wiencheck commented 6 months ago

This crash is affecting a lot of my users however I've not been able to reproduce it on my side. The crash cause is Swift runtime failure: Stride size must not be zero

Screenshot 2024-05-20 at 09 49 43
Peter-Schorn commented 6 months ago

I have identified the root cause of this bug and will deploy a fix soon. It's caused by Spotify returning a value of 0 in the JSON payload for the PagingObject.limit property, which specifies the maximum number of items in the current page (and the step for the page offset interval). You cannot iterate over an interval with a step of 0.

Peter-Schorn commented 6 months ago

Please Try 4297eb6f4161fc0f813bf76ce9d4cf8d5cc13f7c. Should now be fixed in 3.0.1. Please close if this fixes your issue.

wiencheck commented 6 months ago

It seems that those changes broke the extendPages functionality because now it only downloads first page and returns. I rolled back to 3.0.0 and then was able to download all pages from PagingObject so 3.0.1 definitely broke some logic

Peter-Schorn commented 6 months ago

Oh noo. Will take a look.

Peter-Schorn commented 6 months ago

I think this is the issue: https://github.com/Peter-Schorn/SpotifyAPI/blob/9cc938b41d50eeb5ef8d25431d1d084100f40cc8/Sources/SpotifyWebAPI/Other/MiscellaneousUtilities.swift#L256-L258

This was supposed to be:

if minOffset >= maxOffset {
    return []
}

This will prevent crashes.

Peter-Schorn commented 6 months ago

Please try https://github.com/Peter-Schorn/SpotifyAPI/commit/39fd1be211ff355ee29b67abcdacf38b45da57d8.

wiencheck commented 6 months ago

After testing it seems that the issue is now resolved, thank you!