Skip to content
Browse files

Fix handling of truncated tags

  • Loading branch information...
1 parent 99dfd79 commit ac2bde25507bdd7760f5df22238ab01bb2a2a021 @CyberShadow committed Sep 29, 2012
Showing with 18 additions and 7 deletions.
  1. +5 −0 CHANGELOG.md
  2. +2 −1 abcreplace.d
  3. +2 −1 swfbinreplace.d
  4. +9 −5 swffile.d
View
5 CHANGELOG.md
@@ -1,6 +1,11 @@
RABCDAsm Changelog
==================
+RABCDAsm v1.13 (2012.09.29)
+---------------------------
+
+ * Fixed handling of truncated SWF tags
+
RABCDAsm v1.12 (2012.09.08)
---------------------------
View
3 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.
*
* RABCDAsm is free software: you can redistribute it and/or modify
@@ -41,6 +41,7 @@ void main(string[] args)
while (*p++) {} // skip name
tag.data = tag.data[0..p-tag.data.ptr] ~ abc;
}
+ tag.length = tag.data.length;
write(args[1], swf.write());
return;
}
View
3 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.
*
* RABCDAsm is free software: you can redistribute it and/or modify
@@ -33,6 +33,7 @@ void main(string[] args)
{
auto bin = cast(ubyte[])read(args[3]);
tag.data = tag.data[0..6] ~ bin;
+ tag.length = tag.data.length;
write(args[1], swf.write());
return;
}
View
14 swffile.d
@@ -65,6 +65,7 @@ final class SWFFile
{
ushort type;
ubyte[] data;
+ uint length; // may be >data.length if file is truncated
bool forceLongLength;
}
@@ -129,10 +130,12 @@ private final class SWFReader
pos += raw.length;
}
+ /// May read less than len on EOF
void[] readRaw(size_t len)
{
- auto data = buf[pos..pos+len];
- pos += len;
+ auto end = pos+len;
+ auto data = buf[pos..end<$?end:$];
+ pos = end;
return data;
}
@@ -174,6 +177,7 @@ private final class SWFReader
if (length < 0x3F)
t.forceLongLength = true;
}
+ t.length = length;
t.data = cast(ubyte[])readRaw(length);
return t;
}
@@ -263,16 +267,16 @@ private final class SWFWriter
foreach (ref tag; swf.tags)
{
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);
}
else
{
u |= 0x3F;
buf ~= toArray(u);
- uint l = to!uint(tag.data.length);
+ uint l = to!uint(tag.length);
buf ~= toArray(l);
}
buf ~= tag.data;

0 comments on commit ac2bde2

Please sign in to comment.
Something went wrong with that request. Please try again.