Advertisement
Guest User

Untitled

a guest
Jun 7th, 2019
172
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 0595c776095e1fdc4d5626a0c65806893c064197 Mon Sep 17 00:00:00 2001
  2. From: Max Eliaser <max@maxxedout.net>
  3. Date: Thu, 6 Jun 2019 21:17:42 -0700
  4. Subject: [PATCH] Fix infinite retry loop when an album art file won't fit in
  5.  in-memory buffer.
  6.  
  7. The existing error code, ERR_BUFFER_FULL, signified a buffer that was
  8. temporarily too full. It would trigger a flush of buffered files and a reload.
  9.  
  10. However, if the file actually exceeded the buffer size completely, the
  11. allocation for it would never succeed, triggering an infinite loop. The UI
  12. would remain responsive but no music would play.
  13.  
  14. This commit adds a new error code, ERR_BUFFER_TOO_SMALL, which is NOT retried.
  15. It will be used in cases where the buffer is just too small, and no amount of
  16. flushing will make the file fit.
  17.  
  18. Since there is already code to handle if an audio file won't fit in the
  19. buffer, behavior is only altered for image files.
  20. ---
  21. apps/buffering.c |  3 +++
  22.  apps/buffering.h | 11 ++++++-----
  23.  2 files changed, 9 insertions(+), 5 deletions(-)
  24.  
  25. diff --git a/apps/buffering.c b/apps/buffering.c
  26. index 9ffd35714c..6cd3b13f88 100644
  27. --- a/apps/buffering.c
  28. +++ b/apps/buffering.c
  29. @@ -992,6 +992,9 @@ int bufopen(const char *file, off_t offset, enum data_type type,
  30.      /* Reserve extra space because alignment can move data forward */
  31.      size_t padded_size = STORAGE_PAD(size - adjusted_offset);
  32.  
  33. +    if (padded_size > buffer_len && type == TYPE_BITMAP)
  34. +        return ERR_BUFFER_TOO_SMALL;
  35. +
  36.      mutex_lock(&llist_mutex);
  37.  
  38.      h = add_handle(hflags, padded_size, file, &data);
  39. diff --git a/apps/buffering.h b/apps/buffering.h
  40. index fcffcf086c..692d8fa785 100644
  41. --- a/apps/buffering.h
  42. +++ b/apps/buffering.h
  43. @@ -42,11 +42,12 @@ enum data_type {
  44.  /* Error return values */
  45.  #define ERR_HANDLE_NOT_FOUND    -1
  46.  #define ERR_BUFFER_FULL         -2
  47. -#define ERR_INVALID_VALUE       -3
  48. -#define ERR_FILE_ERROR          -4
  49. -#define ERR_HANDLE_NOT_DONE     -5
  50. -#define ERR_UNSUPPORTED_TYPE    -6
  51. -#define ERR_WRONG_THREAD        -7
  52. +#define ERR_BUFFER_TOO_SMALL    -3
  53. +#define ERR_INVALID_VALUE       -4
  54. +#define ERR_FILE_ERROR          -5
  55. +#define ERR_HANDLE_NOT_DONE     -6
  56. +#define ERR_UNSUPPORTED_TYPE    -7
  57. +#define ERR_WRONG_THREAD        -8
  58.  
  59.  /* Initialise the buffering subsystem */
  60.  void buffering_init(void) INIT_ATTR;
  61. --
  62. 2.20.1
Advertisement
RAW Paste Data Copied
Advertisement