Klaus Demo nginx / 7ae525b
Mp4: sanity checks cleanup. Maxim Dounin 10 years ago
1 changed file(s) with 219 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
155155
156156 #define ngx_mp4_atom_header(mp4) (mp4->buffer_pos - 8)
157157 #define ngx_mp4_atom_data(mp4) mp4->buffer_pos
158 #define ngx_mp4_atom_data_size(t) (uint64_t) (sizeof(t) - 8)
158159 #define ngx_mp4_atom_next(mp4, n) mp4->buffer_pos += n; mp4->offset += n
159160
160161
203204 static ngx_int_t ngx_http_mp4_process(ngx_http_mp4_file_t *mp4);
204205 static ngx_int_t ngx_http_mp4_read_atom(ngx_http_mp4_file_t *mp4,
205206 ngx_http_mp4_atom_handler_t *atom, uint64_t atom_data_size);
206 static ngx_int_t ngx_http_mp4_read(ngx_http_mp4_file_t *mp4);
207 static ngx_int_t ngx_http_mp4_read(ngx_http_mp4_file_t *mp4, size_t size);
207208 static ngx_int_t ngx_http_mp4_read_ftyp_atom(ngx_http_mp4_file_t *mp4,
208209 uint64_t atom_data_size);
209210 static ngx_int_t ngx_http_mp4_read_moov_atom(ngx_http_mp4_file_t *mp4,
264265 ngx_http_mp4_trak_t *trak);
265266 static ngx_int_t ngx_http_mp4_read_stsz_atom(ngx_http_mp4_file_t *mp4,
266267 uint64_t atom_data_size);
267 static void ngx_http_mp4_update_stsz_atom(ngx_http_mp4_file_t *mp4,
268 static ngx_int_t ngx_http_mp4_update_stsz_atom(ngx_http_mp4_file_t *mp4,
268269 ngx_http_mp4_trak_t *trak);
269270 static ngx_int_t ngx_http_mp4_read_stco_atom(ngx_http_mp4_file_t *mp4,
270271 uint64_t atom_data_size);
700701 return NGX_ERROR;
701702 }
702703
703 ngx_http_mp4_update_stsz_atom(mp4, &trak[i]);
704 if (ngx_http_mp4_update_stsz_atom(mp4, &trak[i]) != NGX_OK) {
705 return NGX_ERROR;
706 }
704707
705708 if (trak[i].out[NGX_HTTP_MP4_CO64_DATA].buf) {
706709 if (ngx_http_mp4_update_co64_atom(mp4, &trak[i]) != NGX_OK) {
792795
793796 while (mp4->offset < end) {
794797
795 if (mp4->buffer_pos + sizeof(uint32_t) > mp4->buffer_end) {
796 if (ngx_http_mp4_read(mp4) != NGX_OK) {
797 return NGX_ERROR;
798 }
798 if (ngx_http_mp4_read(mp4, sizeof(uint32_t)) != NGX_OK) {
799 return NGX_ERROR;
799800 }
800801
801802 atom_header = mp4->buffer_pos;
812813
813814 if (atom_size == 1) {
814815
815 if (mp4->buffer_pos + sizeof(ngx_mp4_atom_header64_t)
816 > mp4->buffer_end)
816 if (ngx_http_mp4_read(mp4, sizeof(ngx_mp4_atom_header64_t))
817 != NGX_OK)
817818 {
818 if (ngx_http_mp4_read(mp4) != NGX_OK) {
819 return NGX_ERROR;
820 }
821
822 atom_header = mp4->buffer_pos;
819 return NGX_ERROR;
823820 }
824821
825822 /* 64-bit atom size */
823 atom_header = mp4->buffer_pos;
826824 atom_size = ngx_mp4_get_64value(atom_header + 8);
827825 atom_header_size = sizeof(ngx_mp4_atom_header64_t);
828826
834832 }
835833 }
836834
837 if (mp4->buffer_pos + sizeof(ngx_mp4_atom_header_t) > mp4->buffer_end) {
838 if (ngx_http_mp4_read(mp4) != NGX_OK) {
839 return NGX_ERROR;
840 }
841
842 atom_header = mp4->buffer_pos;
843 }
844
835 if (ngx_http_mp4_read(mp4, sizeof(ngx_mp4_atom_header_t)) != NGX_OK) {
836 return NGX_ERROR;
837 }
838
839 atom_header = mp4->buffer_pos;
845840 atom_name = atom_header + sizeof(uint32_t);
846841
847842 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
848843 "mp4 atom: %*s @%O:%uL",
849844 4, atom_name, mp4->offset, atom_size);
845
846 if (atom_size > (uint64_t) (NGX_MAX_OFF_T_VALUE - mp4->offset)
847 || mp4->offset + (off_t) atom_size > end)
848 {
849 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
850 "\"%s\" mp4 atom too large:%uL",
851 mp4->file.name.data, atom_size);
852 return NGX_ERROR;
853 }
850854
851855 for (n = 0; atom[n].name; n++) {
852856
874878
875879
876880 static ngx_int_t
877 ngx_http_mp4_read(ngx_http_mp4_file_t *mp4)
878 {
879 ngx_int_t n;
881 ngx_http_mp4_read(ngx_http_mp4_file_t *mp4, size_t size)
882 {
883 ssize_t n;
884
885 if (mp4->buffer_pos + size <= mp4->buffer_end) {
886 return NGX_OK;
887 }
880888
881889 if (mp4->offset + (off_t) mp4->buffer_size > mp4->end) {
882890 mp4->buffer_size = (size_t) (mp4->end - mp4->offset);
891 }
892
893 if (mp4->buffer_size < size) {
894 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
895 "\"%s\" mp4 file truncated", mp4->file.name.data);
896 return NGX_ERROR;
883897 }
884898
885899 if (mp4->buffer == NULL) {
889903 }
890904
891905 mp4->buffer_start = mp4->buffer;
892 mp4->buffer_end = mp4->buffer + mp4->buffer_size;
893906 }
894907
895908 n = ngx_read_file(&mp4->file, mp4->buffer_start, mp4->buffer_size,
899912 return NGX_ERROR;
900913 }
901914
902 if (n == 0) {
903 return NGX_OK;
915 if ((size_t) n != mp4->buffer_size) {
916 ngx_log_error(NGX_LOG_CRIT, mp4->file.log, 0,
917 ngx_read_file_n " read only %z of %z from \"%s\"",
918 n, mp4->buffer_size, mp4->file.name.data);
919 return NGX_ERROR;
904920 }
905921
906922 mp4->buffer_pos = mp4->buffer_start;
923 mp4->buffer_end = mp4->buffer_start + mp4->buffer_size;
907924
908925 return NGX_OK;
909926 }
918935
919936 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 ftyp atom");
920937
921 if (atom_data_size > 1024) {
938 if (atom_data_size > 1024
939 || ngx_mp4_atom_data(mp4) + atom_data_size > mp4->buffer_end)
940 {
922941 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
923942 "\"%s\" mp4 ftyp atom is too large:%uL",
924943 mp4->file.name.data, atom_data_size);
11671186 mvhd64_atom = (ngx_mp4_mvhd64_atom_t *) atom_header;
11681187 ngx_mp4_set_atom_name(atom_header, 'm', 'v', 'h', 'd');
11691188
1189 if (ngx_mp4_atom_data_size(ngx_mp4_mvhd_atom_t) > atom_data_size) {
1190 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1191 "\"%s\" mp4 mvhd atom too small", mp4->file.name.data);
1192 return NGX_ERROR;
1193 }
1194
11701195 if (mvhd_atom->version[0] == 0) {
11711196 /* version 0: 32-bit duration */
11721197 timescale = ngx_mp4_get_32value(mvhd_atom->timescale);
11741199
11751200 } else {
11761201 /* version 1: 64-bit duration */
1202
1203 if (ngx_mp4_atom_data_size(ngx_mp4_mvhd64_atom_t) > atom_data_size) {
1204 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1205 "\"%s\" mp4 mvhd atom too small",
1206 mp4->file.name.data);
1207 return NGX_ERROR;
1208 }
1209
11771210 timescale = ngx_mp4_get_32value(mvhd64_atom->timescale);
11781211 duration = ngx_mp4_get_64value(mvhd64_atom->duration);
11791212 }
13441377 tkhd64_atom = (ngx_mp4_tkhd64_atom_t *) atom_header;
13451378 ngx_mp4_set_atom_name(tkhd_atom, 't', 'k', 'h', 'd');
13461379
1380 if (ngx_mp4_atom_data_size(ngx_mp4_tkhd_atom_t) > atom_data_size) {
1381 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1382 "\"%s\" mp4 tkhd atom too small", mp4->file.name.data);
1383 return NGX_ERROR;
1384 }
1385
13471386 if (tkhd_atom->version[0] == 0) {
13481387 /* version 0: 32-bit duration */
13491388 duration = ngx_mp4_get_32value(tkhd_atom->duration);
13501389
13511390 } else {
13521391 /* version 1: 64-bit duration */
1392
1393 if (ngx_mp4_atom_data_size(ngx_mp4_tkhd64_atom_t) > atom_data_size) {
1394 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1395 "\"%s\" mp4 tkhd atom too small",
1396 mp4->file.name.data);
1397 return NGX_ERROR;
1398 }
1399
13531400 duration = ngx_mp4_get_64value(tkhd64_atom->duration);
13541401 }
13551402
14731520 mdhd64_atom = (ngx_mp4_mdhd64_atom_t *) atom_header;
14741521 ngx_mp4_set_atom_name(mdhd_atom, 'm', 'd', 'h', 'd');
14751522
1523 if (ngx_mp4_atom_data_size(ngx_mp4_mdhd_atom_t) > atom_data_size) {
1524 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1525 "\"%s\" mp4 mdhd atom too small", mp4->file.name.data);
1526 return NGX_ERROR;
1527 }
1528
14761529 if (mdhd_atom->version[0] == 0) {
14771530 /* version 0: everything is 32-bit */
14781531 timescale = ngx_mp4_get_32value(mdhd_atom->timescale);
14801533
14811534 } else {
14821535 /* version 1: 64-bit duration and 32-bit timescale */
1536
1537 if (ngx_mp4_atom_data_size(ngx_mp4_mdhd64_atom_t) > atom_data_size) {
1538 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1539 "\"%s\" mp4 mdhd atom too small",
1540 mp4->file.name.data);
1541 return NGX_ERROR;
1542 }
1543
14831544 timescale = ngx_mp4_get_32value(mdhd64_atom->timescale);
14841545 duration = ngx_mp4_get_64value(mdhd64_atom->duration);
14851546 }
17551816 ngx_mp4_set_32value(stsd_atom->size, atom_size);
17561817 ngx_mp4_set_atom_name(stsd_atom, 's', 't', 's', 'd');
17571818
1758 if ((uint64_t) (sizeof(ngx_mp4_stsd_atom_t) - sizeof(ngx_mp4_atom_header_t))
1759 > atom_data_size)
1760 {
1819 if (ngx_mp4_atom_data_size(ngx_mp4_stsd_atom_t) > atom_data_size) {
17611820 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1762 "\"%s\" mp4 stsd atom too large",
1763 mp4->file.name.data);
1821 "\"%s\" mp4 stsd atom too small", mp4->file.name.data);
17641822 return NGX_ERROR;
17651823 }
17661824
18241882 stts_atom = (ngx_mp4_stts_atom_t *) atom_header;
18251883 ngx_mp4_set_atom_name(stts_atom, 's', 't', 't', 's');
18261884
1885 if (ngx_mp4_atom_data_size(ngx_mp4_stts_atom_t) > atom_data_size) {
1886 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1887 "\"%s\" mp4 stts atom too small", mp4->file.name.data);
1888 return NGX_ERROR;
1889 }
1890
18271891 entries = ngx_mp4_get_32value(stts_atom->entries);
18281892
18291893 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
18301894 "mp4 time-to-sample entries:%uD", entries);
18311895
1896 if (ngx_mp4_atom_data_size(ngx_mp4_stts_atom_t)
1897 + entries * sizeof(ngx_mp4_stts_entry_t) > atom_data_size)
1898 {
1899 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1900 "\"%s\" mp4 stts atom too small", mp4->file.name.data);
1901 return NGX_ERROR;
1902 }
1903
18321904 atom_table = atom_header + sizeof(ngx_mp4_stts_atom_t);
18331905 atom_end = atom_table + entries * sizeof(ngx_mp4_stts_entry_t);
1834
1835 if ((uint64_t) (atom_end - stts_atom->version) > atom_data_size) {
1836 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1837 "\"%s\" mp4 stts atom too large",
1838 mp4->file.name.data);
1839 return NGX_ERROR;
1840 }
18411906
18421907 trak = ngx_mp4_last_trak(mp4);
18431908 trak->time_to_sample_entries = entries;
19722037 stss_atom = (ngx_http_mp4_stss_atom_t *) atom_header;
19732038 ngx_mp4_set_atom_name(stss_atom, 's', 't', 's', 's');
19742039
2040 if (ngx_mp4_atom_data_size(ngx_http_mp4_stss_atom_t) > atom_data_size) {
2041 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2042 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
2043 return NGX_ERROR;
2044 }
2045
19752046 entries = ngx_mp4_get_32value(stss_atom->entries);
19762047
19772048 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
19872058 atom->pos = atom_header;
19882059 atom->last = atom_table;
19892060
2061 if (ngx_mp4_atom_data_size(ngx_http_mp4_stss_atom_t)
2062 + entries * sizeof(uint32_t) > atom_data_size)
2063 {
2064 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2065 "\"%s\" mp4 stss atom too small", mp4->file.name.data);
2066 return NGX_ERROR;
2067 }
2068
19902069 atom_end = atom_table + entries * sizeof(uint32_t);
1991
1992 if ((uint64_t) (atom_end - stss_atom->version) > atom_data_size) {
1993 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
1994 "\"%s\" mp4 stss atom too large", mp4->file.name.data);
1995 return NGX_ERROR;
1996 }
19972070
19982071 data = &trak->stss_data_buf;
19992072 data->temporary = 1;
21172190 ctts_atom = (ngx_mp4_ctts_atom_t *) atom_header;
21182191 ngx_mp4_set_atom_name(ctts_atom, 'c', 't', 't', 's');
21192192
2193 if (ngx_mp4_atom_data_size(ngx_mp4_ctts_atom_t) > atom_data_size) {
2194 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2195 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
2196 return NGX_ERROR;
2197 }
2198
21202199 entries = ngx_mp4_get_32value(ctts_atom->entries);
21212200
21222201 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
21322211 atom->pos = atom_header;
21332212 atom->last = atom_table;
21342213
2214 if (ngx_mp4_atom_data_size(ngx_mp4_ctts_atom_t)
2215 + entries * sizeof(ngx_mp4_ctts_entry_t) > atom_data_size)
2216 {
2217 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2218 "\"%s\" mp4 ctts atom too small", mp4->file.name.data);
2219 return NGX_ERROR;
2220 }
2221
21352222 atom_end = atom_table + entries * sizeof(ngx_mp4_ctts_entry_t);
2136
2137 if ((uint64_t) (atom_end - ctts_atom->version) > atom_data_size) {
2138 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2139 "\"%s\" mp4 ctts atom too large", mp4->file.name.data);
2140 return NGX_ERROR;
2141 }
21422223
21432224 data = &trak->ctts_data_buf;
21442225 data->temporary = 1;
22502331 stsc_atom = (ngx_mp4_stsc_atom_t *) atom_header;
22512332 ngx_mp4_set_atom_name(stsc_atom, 's', 't', 's', 'c');
22522333
2334 if (ngx_mp4_atom_data_size(ngx_mp4_stsc_atom_t) > atom_data_size) {
2335 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2336 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
2337 return NGX_ERROR;
2338 }
2339
22532340 entries = ngx_mp4_get_32value(stsc_atom->entries);
22542341
22552342 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
22562343 "sample-to-chunk entries:%uD", entries);
22572344
2345 if (ngx_mp4_atom_data_size(ngx_mp4_stsc_atom_t)
2346 + entries * sizeof(ngx_mp4_stsc_entry_t) > atom_data_size)
2347 {
2348 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2349 "\"%s\" mp4 stsc atom too small", mp4->file.name.data);
2350 return NGX_ERROR;
2351 }
2352
22582353 atom_table = atom_header + sizeof(ngx_mp4_stsc_atom_t);
22592354 atom_end = atom_table + entries * sizeof(ngx_mp4_stsc_entry_t);
2260
2261 if ((uint64_t) (atom_end - stsc_atom->version) > atom_data_size) {
2262 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2263 "\"%s\" mp4 stsc atom too large",
2264 mp4->file.name.data);
2265 return NGX_ERROR;
2266 }
22672355
22682356 trak = ngx_mp4_last_trak(mp4);
22692357 trak->sample_to_chunk_entries = entries;
23122400 if (data == NULL) {
23132401 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
23142402 "no mp4 stsc atoms were found in \"%s\"",
2403 mp4->file.name.data);
2404 return NGX_ERROR;
2405 }
2406
2407 if (trak->sample_to_chunk_entries == 0) {
2408 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2409 "zero number of entries in stsc atom in \"%s\"",
23152410 mp4->file.name.data);
23162411 return NGX_ERROR;
23172412 }
24572552 stsz_atom = (ngx_mp4_stsz_atom_t *) atom_header;
24582553 ngx_mp4_set_atom_name(stsz_atom, 's', 't', 's', 'z');
24592554
2555 if (ngx_mp4_atom_data_size(ngx_mp4_stsz_atom_t) > atom_data_size) {
2556 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2557 "\"%s\" mp4 stsz atom too small", mp4->file.name.data);
2558 return NGX_ERROR;
2559 }
2560
24602561 size = ngx_mp4_get_32value(stsz_atom->uniform_size);
24612562 entries = ngx_mp4_get_32value(stsz_atom->entries);
24622563
24762577 trak->out[NGX_HTTP_MP4_STSZ_ATOM].buf = atom;
24772578
24782579 if (size == 0) {
2479 atom_end = atom_table + entries * sizeof(uint32_t);
2480
2481 if ((uint64_t) (atom_end - stsz_atom->version) > atom_data_size) {
2580 if (ngx_mp4_atom_data_size(ngx_mp4_stsz_atom_t)
2581 + entries * sizeof(uint32_t) > atom_data_size)
2582 {
24822583 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2483 "\"%s\" mp4 stsz atom too large",
2584 "\"%s\" mp4 stsz atom too small",
24842585 mp4->file.name.data);
24852586 return NGX_ERROR;
24862587 }
2588
2589 atom_end = atom_table + entries * sizeof(uint32_t);
24872590
24882591 data = &trak->stsz_data_buf;
24892592 data->temporary = 1;
25062609 }
25072610
25082611
2509 static void
2612 static ngx_int_t
25102613 ngx_http_mp4_update_stsz_atom(ngx_http_mp4_file_t *mp4,
25112614 ngx_http_mp4_trak_t *trak)
25122615 {
25272630 data = trak->out[NGX_HTTP_MP4_STSZ_DATA].buf;
25282631
25292632 if (data) {
2633 if (trak->start_sample > trak->sample_sizes_entries) {
2634 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2635 "start time is out mp4 stsz samples in \"%s\"",
2636 mp4->file.name.data);
2637 return NGX_ERROR;
2638 }
2639
25302640 data->pos += trak->start_sample * sizeof(uint32_t);
25312641 end = (uint32_t *) data->pos;
25322642
25472657 ngx_mp4_set_32value(stsz_atom->entries,
25482658 trak->sample_sizes_entries - trak->start_sample);
25492659 }
2660
2661 return NGX_OK;
25502662 }
25512663
25522664
25762688 stco_atom = (ngx_mp4_stco_atom_t *) atom_header;
25772689 ngx_mp4_set_atom_name(stco_atom, 's', 't', 'c', 'o');
25782690
2691 if (ngx_mp4_atom_data_size(ngx_mp4_stco_atom_t) > atom_data_size) {
2692 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2693 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
2694 return NGX_ERROR;
2695 }
2696
25792697 entries = ngx_mp4_get_32value(stco_atom->entries);
25802698
25812699 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "chunks:%uD", entries);
2700
2701 if (ngx_mp4_atom_data_size(ngx_mp4_stco_atom_t)
2702 + entries * sizeof(uint32_t) > atom_data_size)
2703 {
2704 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2705 "\"%s\" mp4 stco atom too small", mp4->file.name.data);
2706 return NGX_ERROR;
2707 }
25822708
25832709 atom_table = atom_header + sizeof(ngx_mp4_stco_atom_t);
25842710 atom_end = atom_table + entries * sizeof(uint32_t);
2585
2586 if ((uint64_t) (atom_end - stco_atom->version) > atom_data_size) {
2587 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2588 "\"%s\" mp4 stco atom too large", mp4->file.name.data);
2589 return NGX_ERROR;
2590 }
25912711
25922712 trak = ngx_mp4_last_trak(mp4);
25932713 trak->chunks = entries;
26332753 if (data == NULL) {
26342754 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
26352755 "no mp4 stco atoms were found in \"%s\"",
2756 mp4->file.name.data);
2757 return NGX_ERROR;
2758 }
2759
2760 if (trak->start_chunk > trak->chunks) {
2761 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2762 "start time is out mp4 stco chunks in \"%s\"",
26362763 mp4->file.name.data);
26372764 return NGX_ERROR;
26382765 }
27122839 co64_atom = (ngx_mp4_co64_atom_t *) atom_header;
27132840 ngx_mp4_set_atom_name(co64_atom, 'c', 'o', '6', '4');
27142841
2842 if (ngx_mp4_atom_data_size(ngx_mp4_co64_atom_t) > atom_data_size) {
2843 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2844 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
2845 return NGX_ERROR;
2846 }
2847
27152848 entries = ngx_mp4_get_32value(co64_atom->entries);
27162849
27172850 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "chunks:%uD", entries);
2851
2852 if (ngx_mp4_atom_data_size(ngx_mp4_co64_atom_t)
2853 + entries * sizeof(uint64_t) > atom_data_size)
2854 {
2855 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2856 "\"%s\" mp4 co64 atom too small", mp4->file.name.data);
2857 return NGX_ERROR;
2858 }
27182859
27192860 atom_table = atom_header + sizeof(ngx_mp4_co64_atom_t);
27202861 atom_end = atom_table + entries * sizeof(uint64_t);
2721
2722 if ((uint64_t) (atom_end - co64_atom->version) > atom_data_size) {
2723 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2724 "\"%s\" mp4 co64 atom too large", mp4->file.name.data);
2725 return NGX_ERROR;
2726 }
27272862
27282863 trak = ngx_mp4_last_trak(mp4);
27292864 trak->chunks = entries;
27732908 return NGX_ERROR;
27742909 }
27752910
2911 if (trak->start_chunk > trak->chunks) {
2912 ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
2913 "start time is out mp4 co64 chunks in \"%s\"",
2914 mp4->file.name.data);
2915 return NGX_ERROR;
2916 }
2917
27762918 data->pos += trak->start_chunk * sizeof(uint64_t);
27772919 atom_size = sizeof(ngx_mp4_co64_atom_t) + (data->last - data->pos);
27782920 trak->size += atom_size;