mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
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
This commit is contained in:
parent
3b1e95d480
commit
b1fac21e4e
1 changed files with 5 additions and 6 deletions
|
|
@ -761,8 +761,7 @@ static int add_indices_to_playlist(struct playlist_info* playlist,
|
||||||
char* buffer, size_t buflen)
|
char* buffer, size_t buflen)
|
||||||
{
|
{
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
unsigned int i = 0;
|
unsigned int i, count = 0;
|
||||||
unsigned int count = 0;
|
|
||||||
bool store_index;
|
bool store_index;
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
@ -772,18 +771,18 @@ static int add_indices_to_playlist(struct playlist_info* playlist,
|
||||||
|
|
||||||
playlist_write_lock(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)
|
if (pl_open_playlist(playlist) < 0)
|
||||||
{
|
{
|
||||||
result = -1;
|
result = -1;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* seek to the beginning of the file get_filename leaves it elsewhere */
|
i = lseek(playlist->fd, 0, SEEK_CUR);
|
||||||
i = lseek(playlist->fd, playlist->utf8 ? BOM_UTF_8_SIZE : 0, SEEK_SET);
|
|
||||||
|
|
||||||
splash(0, ID2P(LANG_WAIT));
|
splash(0, ID2P(LANG_WAIT));
|
||||||
|
|
||||||
store_index = true;
|
store_index = true;
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue