Files
BuildTools
Qt
Src
Agave
Components
Elevator
Mastering
Plugins
ReplayGainAnalysis
WAT
Wasabi
Wasabi2
Winamp
aacPlus
aacdec
aacdec-mft
adpcm
alac
albumart
apev2
auth
bmp
burnlib
codesign
config
devices
external_dependencies
f263
filereader
freetypewac
gif
gracenote
h264
h264dec
id3v2
ie_plugin
installer
jpeg
libvp6
libvpShared
mp3-mpg123
mp4v
mpeg4dec
nde
nprt_plugin
ns-eel
ns-eel2
nsavi
nsmkv
Attachments.cpp
Attachments.h
Chapters.cpp
Chapters.h
Cluster.cpp
Cluster.h
Cues.cpp
Cues.h
Lacing.cpp
Lacing.h
SeekTable.cpp
SeekTable.h
SegmentInfo.cpp
SegmentInfo.h
Tags.cpp
Tags.h
Tracks.cpp
Tracks.h
ebml_float.cpp
ebml_float.h
ebml_signed.cpp
ebml_signed.h
ebml_unsigned.cpp
ebml_unsigned.h
file_mkv_reader.cpp
file_mkv_reader.h
global_elements.cpp
global_elements.h
header.cpp
header.h
main.cpp
mkv_date.cpp
mkv_date.h
mkv_reader.h
nsmkv.h
nsmkv.sln
nsmkv.vcxproj
nsmkv.vcxproj.filters
read.cpp
read.h
segment.h
vint.cpp
vint.h
nsutil
nsv
nsvdec_vp3
nsvdec_vp5
nsvdec_vp6
nswasabi
nu
omBrowser
pcm
pfc
playlist
plist
png
replicant
resources
tagz
tataki
theora
timer
vlb
vp32
vp6
vp8x
wbm
winampAll
winampa
xml
xspf
vcpkg-ports
.gitignore
LICENSE.md
README.md
automate-git.py
cef_x86.bat
install-packages.cmd
vcpkg_version_finder.py
winampAll_2019.sln
winamp/Src/nsmkv/Attachments.cpp
2024-09-24 14:54:57 +02:00

109 lines
2.4 KiB
C++

#include "Attachments.h"
#include "read.h"
#include "global_elements.h"
static uint64_t ReadAttachedFile(nsmkv::MKVReader *reader, uint64_t size, nsmkv::AttachedFile &attached_file)
{
uint64_t total_bytes_read=0;
while (size)
{
ebml_node node;
uint64_t bytes_read = read_ebml_node(reader, &node);
if (bytes_read == 0)
return 0;
// benski> checking bytes_read and node.size separately prevents possible integer overflow attack
if (bytes_read > size)
return 0;
total_bytes_read+=bytes_read;
size-=bytes_read;
if (node.size > size)
return 0;
total_bytes_read+=node.size;
size-=node.size;
switch(node.id)
{
case mkv_attachments_filename:
{
char *utf8 = 0;
if (read_utf8(reader, node.size, &utf8) == 0)
return 0;
if (utf8)
printf("Filename: %s\n", utf8);
attached_file.Own(attached_file.filename, utf8);
}
break;
case mkv_attachments_filemimetype:
{
char *utf8 = 0;
if (read_utf8(reader, node.size, &utf8) == 0)
return 0;
if (utf8)
printf("File MIME Type: %s\n", utf8);
attached_file.Own(attached_file.mime_type, utf8);
}
break;
case mkv_attachments_filedata:
{
printf("File Data: binary size %I64u\n", node.size);
reader->Skip(node.size);
}
break;
case mkv_attachments_fileuid:
{
uint64_t val;
if (read_unsigned(reader, node.size, &val) == 0)
return 0;
printf("File UID: %I64x\n", val);
attached_file.file_uid = val;
}
break;
default:
nsmkv::ReadGlobal(reader, node.id, node.size);
}
}
return total_bytes_read;
}
uint64_t nsmkv::ReadAttachment(nsmkv::MKVReader *reader, uint64_t size, nsmkv::Attachments &attachments)
{
uint64_t total_bytes_read=0;
while (size)
{
ebml_node node;
uint64_t bytes_read = read_ebml_node(reader, &node);
if (bytes_read == 0)
return 0;
// benski> checking bytes_read and node.size separately prevents possible integer overflow attack
if (bytes_read > size)
return 0;
total_bytes_read+=bytes_read;
size-=bytes_read;
if (node.size > size)
return 0;
total_bytes_read+=node.size;
size-=node.size;
switch(node.id)
{
case mkv_attachments_attachedfile:
{
printf("Attachmented File\\n");
nsmkv::AttachedFile attached_file;
ReadAttachedFile(reader, node.size, attached_file);
}
break;
default:
ReadGlobal(reader, node.id, node.size);
}
}
return total_bytes_read;
}