invidious icon indicating copy to clipboard operation
invidious copied to clipboard

[Bug] Index out of bounds (IndexError) in preferences.cr

Open 4-FLOSS-Free-Libre-Open-Source-Software opened this issue 3 years ago • 4 comments

Describe the bug

Steps to Reproduce

Invidious Looks like you've found a bug in Invidious. Please open a new issue on GitHub and include the following text in your message:

Title: Index out of bounds (IndexError) Route: /preferences?referer=%2Ffeed%2Ftrending Version: 2021.04.06-ae353ce @ master

Backtrace

Index out of bounds (IndexError)
  from src/invidious/routes/preferences.cr:13:22 in 'update'
  from lib/kemal/src/kemal/route.cr:12:9 in '->'
  from /usr/share/crystal/src/primitives.cr:255:3 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/filter_handler.cr:21:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/static_file_handler.cr:112:11 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/init_handler.cr:12:7 in 'process'
  from /usr/share/crystal/src/http/server.cr:498:5 in '->'
  from /usr/share/crystal/src/primitives.cr:255:3 in 'run'
  from ???

Duplicate of #1798

syeopite avatar Apr 08 '21 04:04 syeopite

This is not a duplicate, the error happens in the same file but in a different place.

The first invidious source file the backtrace references is src/invidious/routes/preferences.cr line 13, column 22:

from src/invidious/routes/preferences.cr:13:22 in 'update'

The commit is ae353cef2e3013bc1d995d3c607e7ef2b76f7ffe and the code is: https://github.com/iv-org/invidious/blob/ae353cef2e3013bc1d995d3c607e7ef2b76f7ffe/src/invidious/routes/preferences.cr#L13

 locale = LOCALES[env.get("preferences").as(Preferences).locale]? 
                     ^ column 22

So the Index out of bounds (IndexError) happens at:

env.get("preferences")

env.get is part of Kemal's HTTP::Server::Context class, see https://github.com/kemalcr/kemal/blob/fe606839653a4900f3cb916171d2227c25de55d2/src/kemal/ext/context.cr#L50 and just tries to read preferences that have been set with env.set. This happens somewhere in here: https://github.com/iv-org/invidious/blob/ae353cef2e3013bc1d995d3c607e7ef2b76f7ffe/src/invidious.cr#L197-L306

My guess is that this was a fluke, since there is no path where env.set("preferences") isn't called. @4-FLOSS-Free-Libre-Open-Source-Software can you reproduce this error?

saltycrys avatar May 18 '21 00:05 saltycrys

The preferences (and their URL override) needs to be rewritten. It's one of my goals after I finish my current draft PRs and the channels rewrite.

SamantazFox avatar Jun 18 '21 12:06 SamantazFox

This issue has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this issue is still relevant and applicable, you just have to post a comment and it will be unmarked.

github-actions[bot] avatar Jun 18 '22 12:06 github-actions[bot]