From a4fe6875a1dfc60cbf6c60eb26b697a8c36aeff4 Mon Sep 17 00:00:00 2001 From: Carl Suster Date: Mon, 1 Apr 2019 17:41:25 +1100 Subject: [PATCH] bpd: fix bug in bounds check of current song index The songs are indexed starting from zero for the play command, however the bound check was off by one. An index matching the length of the playlist would crash the server instead of responding with an error message over the protocol. --- beetsplug/bpd/__init__.py | 2 +- test/test_player.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/beetsplug/bpd/__init__.py b/beetsplug/bpd/__init__.py index c43d24fd5..9b21fae9d 100644 --- a/beetsplug/bpd/__init__.py +++ b/beetsplug/bpd/__init__.py @@ -569,7 +569,7 @@ class BaseServer(object): """Begin playback, possibly at a specified playlist index.""" index = cast_arg(int, index) - if index < -1 or index > len(self.playlist): + if index < -1 or index >= len(self.playlist): raise ArgumentIndexError() if index == -1: # No index specified: start where we are. diff --git a/test/test_player.py b/test/test_player.py index 7707a825c..5e196debd 100644 --- a/test/test_player.py +++ b/test/test_player.py @@ -525,14 +525,17 @@ class BPDControlTest(BPDTestHelper): def test_cmd_play(self): with self.run_bpd() as client: - self._bpd_add(client, self.item1) + self._bpd_add(client, self.item1, self.item2) responses = client.send_commands( ('status',), ('play',), - ('status',)) + ('status',), + ('play', '1'), + ('currentsong',)) self._assert_ok(*responses) self.assertEqual('stop', responses[0].data['state']) self.assertEqual('play', responses[2].data['state']) + self.assertEqual('2', responses[4].data['Id']) def test_cmd_next(self): with self.run_bpd() as client: