Coverage Report

Created: 2026-06-30 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/wiretap/mp4.c
Line
Count
Source
1
/* mp4.c
2
 *
3
 * MP4 (ISO/IEC 14496-12) file format decoder for the Wiretap library.
4
 *
5
 * Wiretap Library
6
 *
7
 * SPDX-License-Identifier: GPL-2.0-or-later
8
 */
9
10
#include "mp4.h"
11
12
#include <string.h>
13
14
#include "file_wrappers.h"
15
#include "wtap_module.h"
16
17
static const uint8_t mp4_magic[] = { 'f', 't', 'y', 'p' };
18
static const uint8_t mp4_magic_sidx[] = { 's', 'i', 'd', 'x' };
19
static const uint8_t mp4_magic_styp[] = { 's', 't', 'y', 'p' };
20
21
static int mp4_file_type_subtype = -1;
22
23
void register_mp4(void);
24
25
wtap_open_return_val
26
mp4_open(wtap *wth, int *err, char **err_info)
27
0
{
28
0
  char magic_buf[8];
29
0
  int bytes_read;
30
31
0
  bytes_read = file_read(magic_buf, sizeof (magic_buf), wth->fh);
32
33
0
  if (bytes_read < 0) {
34
0
    *err = file_error(wth->fh, err_info);
35
0
    return WTAP_OPEN_ERROR;
36
0
  }
37
0
  if (bytes_read == 0)
38
0
    return WTAP_OPEN_NOT_MINE;
39
40
0
  if (bytes_read == sizeof (magic_buf) &&
41
0
      memcmp(magic_buf + 4, mp4_magic, sizeof (mp4_magic)) &&
42
0
      memcmp(magic_buf + 4, mp4_magic_sidx, sizeof (mp4_magic_sidx)) &&
43
0
      memcmp(magic_buf + 4, mp4_magic_styp, sizeof (mp4_magic_styp)))
44
0
    return WTAP_OPEN_NOT_MINE;
45
46
0
  if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
47
0
    return WTAP_OPEN_ERROR;
48
49
0
  wth->file_type_subtype = mp4_file_type_subtype;
50
0
  wth->file_encap = WTAP_ENCAP_MP4;
51
0
  wth->file_tsprec = WTAP_TSPREC_SEC;
52
0
  wth->subtype_read = wtap_full_file_read;
53
0
  wth->subtype_seek_read = wtap_full_file_seek_read;
54
0
  wth->snapshot_length = 0;
55
56
0
  return WTAP_OPEN_MINE;
57
0
}
58
59
static const struct supported_block_type mp4_blocks_supported[] = {
60
  /*
61
   * This is a file format that we dissect, so we provide
62
   * only one "packet" with the file's contents, and don't
63
   * support any options.
64
   */
65
  { WTAP_BLOCK_PACKET, ONE_BLOCK_SUPPORTED, NO_OPTIONS_SUPPORTED }
66
};
67
68
static const struct file_type_subtype_info mp4_info = {
69
  "MP4 media", "mp4", "mp4", NULL,
70
  false, BLOCKS_SUPPORTED(mp4_blocks_supported),
71
  NULL, NULL, NULL
72
};
73
74
void register_mp4(void)
75
14
{
76
14
  mp4_file_type_subtype = wtap_register_file_type_subtype(&mp4_info);
77
78
  /*
79
   * Register name for backwards compatibility with the
80
   * wtap_filetypes table in Lua.
81
   */
82
14
  wtap_register_backwards_compatibility_lua_name("MP4",
83
14
      mp4_file_type_subtype);
84
14
}
85
86
/*
87
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
88
 *
89
 * Local variables:
90
 * c-basic-offset: 8
91
 * tab-width: 8
92
 * indent-tabs-mode: t
93
 * End:
94
 *
95
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
96
 * :indentSize=8:tabSize=8:noTabs=false:
97
 */