This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 9de560e214bdeaec886afe5a2a11d374ff3b2482
Author: jiangbo11 <[email protected]>
AuthorDate: Mon Jul 14 19:27:37 2025 +0800

    nxplayer_mp3: check the return value of lseek() and read()
    
    The ID3v2 tag is skipped by seeking and reading four bytes back, but
    neither the seek nor the read was checked.  Return an error when the
    seek fails, and when fewer than four bytes could be read, instead of
    running the frame sync scan on a buffer that was never filled.
    
    Signed-off-by: jiangbo11 <[email protected]>
---
 system/nxplayer/nxplayer_mp3.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/system/nxplayer/nxplayer_mp3.c b/system/nxplayer/nxplayer_mp3.c
index 582c783b2..8778cf819 100644
--- a/system/nxplayer/nxplayer_mp3.c
+++ b/system/nxplayer/nxplayer_mp3.c
@@ -253,9 +253,19 @@ int nxplayer_parse_mp3(FAR struct nxplayer_s *pplayer, int 
fd,
                  (buffer[9] & ID3V2_BIT_MASK) +
                  sizeof(buffer);
 
-      lseek(fd, position, SEEK_SET);
-      read(fd, buffer, 4);
+      position = lseek(fd, position, SEEK_SET);
+      if (position < 0)
+        {
+          return -errno;
+        }
+
+      ret = read(fd, buffer, 4);
+      if (ret < 4)
+        {
+          return -ENODATA;
+        }
     }
+
   else
     {
       position = 0;
@@ -272,7 +282,12 @@ int nxplayer_parse_mp3(FAR struct nxplayer_s *pplayer, int 
fd,
       return ret;
     }
 
-  lseek(fd, position, SEEK_SET);
+  position = lseek(fd, position, SEEK_SET);
+  if (position < 0)
+    {
+      return -errno;
+    }
+
   return OK;
 }
 

Reply via email to