Skip to content

Commit

Permalink
Fix handling of truncated tags
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Sep 29, 2012
1 parent 99dfd79 commit ac2bde2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
RABCDAsm Changelog RABCDAsm Changelog
================== ==================


RABCDAsm v1.13 (2012.09.29)
---------------------------

* Fixed handling of truncated SWF tags

RABCDAsm v1.12 (2012.09.08) RABCDAsm v1.12 (2012.09.08)
--------------------------- ---------------------------


Expand Down
3 changes: 2 additions & 1 deletion abcreplace.d
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010, 2011 Vladimir Panteleev <vladimir@thecybershadow.net> * Copyright 2010, 2011, 2012 Vladimir Panteleev <vladimir@thecybershadow.net>
* This file is part of RABCDAsm. * This file is part of RABCDAsm.
* *
* RABCDAsm is free software: you can redistribute it and/or modify * RABCDAsm is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -41,6 +41,7 @@ void main(string[] args)
while (*p++) {} // skip name while (*p++) {} // skip name
tag.data = tag.data[0..p-tag.data.ptr] ~ abc; tag.data = tag.data[0..p-tag.data.ptr] ~ abc;
} }
tag.length = tag.data.length;
write(args[1], swf.write()); write(args[1], swf.write());
return; return;
} }
Expand Down
3 changes: 2 additions & 1 deletion swfbinreplace.d
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010, 2011 Vladimir Panteleev <vladimir@thecybershadow.net> * Copyright 2010, 2011, 2012 Vladimir Panteleev <vladimir@thecybershadow.net>
* This file is part of RABCDAsm. * This file is part of RABCDAsm.
* *
* RABCDAsm is free software: you can redistribute it and/or modify * RABCDAsm is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,6 +33,7 @@ void main(string[] args)
{ {
auto bin = cast(ubyte[])read(args[3]); auto bin = cast(ubyte[])read(args[3]);
tag.data = tag.data[0..6] ~ bin; tag.data = tag.data[0..6] ~ bin;
tag.length = tag.data.length;
write(args[1], swf.write()); write(args[1], swf.write());
return; return;
} }
Expand Down
14 changes: 9 additions & 5 deletions swffile.d
Expand Up @@ -65,6 +65,7 @@ final class SWFFile
{ {
ushort type; ushort type;
ubyte[] data; ubyte[] data;
uint length; // may be >data.length if file is truncated
bool forceLongLength; bool forceLongLength;
} }


Expand Down Expand Up @@ -129,10 +130,12 @@ private final class SWFReader
pos += raw.length; pos += raw.length;
} }


/// May read less than len on EOF
void[] readRaw(size_t len) void[] readRaw(size_t len)
{ {
auto data = buf[pos..pos+len]; auto end = pos+len;
pos += len; auto data = buf[pos..end<$?end:$];
pos = end;
return data; return data;
} }


Expand Down Expand Up @@ -174,6 +177,7 @@ private final class SWFReader
if (length < 0x3F) if (length < 0x3F)
t.forceLongLength = true; t.forceLongLength = true;
} }
t.length = length;
t.data = cast(ubyte[])readRaw(length); t.data = cast(ubyte[])readRaw(length);
return t; return t;
} }
Expand Down Expand Up @@ -263,16 +267,16 @@ private final class SWFWriter
foreach (ref tag; swf.tags) foreach (ref tag; swf.tags)
{ {
ushort u = cast(ushort)(tag.type << 6); ushort u = cast(ushort)(tag.type << 6);
if (tag.data.length < 0x3F && !tag.forceLongLength) if (tag.length < 0x3F && !tag.forceLongLength)
{ {
u |= tag.data.length; u |= tag.length;
buf ~= toArray(u); buf ~= toArray(u);
} }
else else
{ {
u |= 0x3F; u |= 0x3F;
buf ~= toArray(u); buf ~= toArray(u);
uint l = to!uint(tag.data.length); uint l = to!uint(tag.length);
buf ~= toArray(l); buf ~= toArray(l);
} }
buf ~= tag.data; buf ~= tag.data;
Expand Down

0 comments on commit ac2bde2

Please sign in to comment.