jellyfin icon indicating copy to clipboard operation
jellyfin copied to clipboard

Fix GetItems IndexOutOfRangeException when IDs do not exist

Open lukefor opened this issue 3 years ago • 4 comments

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

lukefor avatar Jul 29 '22 19:07 lukefor

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

nielsvanvelzen avatar Jul 29 '22 19:07 nielsvanvelzen

Have retargeted it to release-10.8.z now

lukefor avatar Jul 29 '22 19:07 lukefor

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

cvium avatar Jul 29 '22 20:07 cvium

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

cvium avatar Aug 10 '22 07:08 cvium

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

lukefor avatar Aug 17 '22 23:08 lukefor