diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2023-03-30 12:14:58 +0100 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2023-07-02 12:15:57 -0400 |
commit | b1fac21e4e43aa800e162e80532b8f3e17169748 (patch) | |
tree | d40648c7f5568d75096792e6d1b1fde2b3f71673 | |
parent | 3b1e95d4802cd0f5a5df9d4d67696be1af33a14f (diff) | |
download | rockbox-b1fac21e4e.tar.gz rockbox-b1fac21e4e.zip |
playlist: Fix wrong handling of playlists without UTF-8 BOM
add_indices_to_playlist() wrongly assumes playlist->utf8 means
the playlist has a UTF-8 BOM. It only means the file is UTF-8
encoded, and says nothing about the presence of a BOM.
Trying to seek past a BOM when there is none mangles the first
filename in the playlist. Avoid this by closing & reopening the
playlist, which ensures the BOM (or lack of it) gets detected
properly.
Change-Id: I222fa6fc31e941d0252f1895b393a51694b93b7c
-rw-r--r-- | apps/playlist.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index f326d19c23..1314656c83 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -761,8 +761,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist, char* buffer, size_t buflen) { ssize_t nread; - unsigned int i = 0; - unsigned int count = 0; + unsigned int i, count = 0; bool store_index; unsigned char *p; int result = 0; @@ -772,18 +771,18 @@ static int add_indices_to_playlist(struct playlist_info* playlist, playlist_write_lock(playlist); - /* Open playlist file for reading */ + /* Close and re-open the playlist to ensure we are properly + * positioned at the start of the file after any UTF-8 BOM. */ + pl_close_playlist(playlist); if (pl_open_playlist(playlist) < 0) { result = -1; goto exit; } - /* seek to the beginning of the file get_filename leaves it elsewhere */ - i = lseek(playlist->fd, playlist->utf8 ? BOM_UTF_8_SIZE : 0, SEEK_SET); + i = lseek(playlist->fd, 0, SEEK_CUR); splash(0, ID2P(LANG_WAIT)); - store_index = true; while(1) |