]> git.kaiwu.me - nginx.git/commitdiff
Mp4: fixed possible pointer overflow on 32-bit platforms.
authorMaxim Dounin <mdounin@mdounin.ru>
Wed, 21 Nov 2018 17:23:16 +0000 (20:23 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Wed, 21 Nov 2018 17:23:16 +0000 (20:23 +0300)
On 32-bit platforms mp4->buffer_pos might overflow when a large
enough (close to 4 gigabytes) atom is being skipped, resulting in
incorrect memory addesses being read further in the code.  In most
cases this results in harmless errors being logged, though may also
result in a segmentation fault if hitting unmapped pages.

To address this, ngx_mp4_atom_next() now only increments mp4->buffer_pos
up to mp4->buffer_end.  This ensures that overflow cannot happen.

src/http/modules/ngx_http_mp4_module.c

index 2a6fafa04c784d1aed0a998761ab16c87e599ef9..618bf787beeba3fbd8062d1299491bf5fe501b13 100644 (file)
@@ -169,7 +169,14 @@ typedef struct {
 
 
 #define ngx_mp4_atom_next(mp4, n)                                             \
-    mp4->buffer_pos += (size_t) n;                                            \
+                                                                              \
+    if (n > (size_t) (mp4->buffer_end - mp4->buffer_pos)) {                   \
+        mp4->buffer_pos = mp4->buffer_end;                                    \
+                                                                              \
+    } else {                                                                  \
+        mp4->buffer_pos += (size_t) n;                                        \
+    }                                                                         \
+                                                                              \
     mp4->offset += n