Skip to content
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

Fix GetItems IndexOutOfRangeException when IDs do not exist #8189

Merged
merged 4 commits into from
Aug 18, 2022

Conversation

lukefor
Copy link
Contributor

@lukefor lukefor commented Jul 29, 2022

Changes
Resolve a System.IndexOutOfRangeException when requesting IDs that do not exist via /Users/.../Items. Previously it was possible for the 'index' values in 'positions' to refer beyond 'size'. It seems the code previously assumed that all requested items exist

[ERR] Error processing request. URL "GET" "/Users/.../Items".
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at MediaBrowser.Controller.Entities.Folder.SortItemsByRequest(InternalItemsQuery query, IReadOnlyList`1 items)
   at MediaBrowser.Controller.Entities.Folder.GetItems(InternalItemsQuery query)
   at Jellyfin.Api.Controllers.ItemsController.GetItems

It caused jellyfin-kodi automatic syncs (i.e. the sync that happens automatically while Kodi is running) to fail as per #3531. I could get a consistent repro by making the same request via curl. With this change, Kodi is automatically syncing again, and the curl request returns correct results.

Issues
Fixes #3531

@nielsvanvelzen
Copy link
Member

Can you retarget this PR to the release-10.8.z branch? That way we can include it in an patch update.

@lukefor lukefor changed the base branch from master to release-10.8.z July 29, 2022 19:28
@lukefor lukefor changed the base branch from release-10.8.z to master July 29, 2022 19:28
… not exist via /Users/.../Items. Previously it was possible for the 'index' values in 'positions' to refer beyond 'size'.

[ERR] Error processing request. URL "GET" "/Users/.../Items".
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at MediaBrowser.Controller.Entities.Folder.SortItemsByRequest(InternalItemsQuery query, IReadOnlyList`1 items)
   at MediaBrowser.Controller.Entities.Folder.GetItems(InternalItemsQuery query)
   at Jellyfin.Api.Controllers.ItemsController.GetItems
@lukefor lukefor changed the base branch from master to release-10.8.z July 29, 2022 19:44
@lukefor
Copy link
Contributor Author

lukefor commented Jul 29, 2022

Have retargeted it to release-10.8.z now

@nielsvanvelzen nielsvanvelzen added the stable backport Backport into the next stable release label Jul 29, 2022
@cvium
Copy link
Member

cvium commented Jul 29, 2022

Am I crazy or could the entire method not be simplified to return items.OrderBy(i => ids.IndexOf(i.Id)).ToArray();?

@cvium
Copy link
Member

cvium commented Aug 10, 2022

@lukefor Have you had a chance to look at my suggestion?

@lukefor
Copy link
Contributor Author

lukefor commented Aug 17, 2022

Have made the suggested change. Problematic curl request is working and returning identical results to the previous fix

@cvium cvium merged commit 527ed06 into jellyfin:release-10.8.z Aug 18, 2022
@jellyfin-bot jellyfin-bot removed the stable backport Backport into the next stable release label Sep 24, 2022
jellyfin-bot pushed a commit that referenced this pull request Sep 24, 2022
Fix GetItems IndexOutOfRangeException when IDs do not exist

Original-merge: 527ed06

Merged-by: Claus Vium <cvium@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
Kakadus pushed a commit to Kakadus/jellyfin that referenced this pull request Oct 2, 2022
Fix GetItems IndexOutOfRangeException when IDs do not exist

Original-merge: 527ed06

Merged-by: Claus Vium <cvium@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on library scan
5 participants