aboutsummaryrefslogtreecommitdiff
path: root/Src/nsmkv/Attachments.cpp
diff options
context:
space:
mode:
authorJean-Francois Mauguit <jfmauguit@mac.com>2024-09-24 09:03:25 -0400
committerGitHub <noreply@github.com>2024-09-24 09:03:25 -0400
commitbab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/nsmkv/Attachments.cpp
parent4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff)
parent20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff)
downloadwinamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/nsmkv/Attachments.cpp')
-rw-r--r--Src/nsmkv/Attachments.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/Src/nsmkv/Attachments.cpp b/Src/nsmkv/Attachments.cpp
new file mode 100644
index 00000000..5f1f8edd
--- /dev/null
+++ b/Src/nsmkv/Attachments.cpp
@@ -0,0 +1,108 @@
+#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;
+}