diff --git a/Source/ZenLib/BitStream.h b/Source/ZenLib/BitStream.h index e23b848..85e24a7 100644 --- a/Source/ZenLib/BitStream.h +++ b/Source/ZenLib/BitStream.h @@ -183,6 +183,8 @@ class BitStream do { Skip(32); + if (BufferUnderRun) + return; HowMany-=32; } while(HowMany>32); diff --git a/Source/ZenLib/BitStream_Fast.h b/Source/ZenLib/BitStream_Fast.h index 9706333..455259e 100644 --- a/Source/ZenLib/BitStream_Fast.h +++ b/Source/ZenLib/BitStream_Fast.h @@ -80,6 +80,9 @@ class BitStream_Fast 0x1f, 0x3f, 0x7f, 0xff, }; + if (HowMany==0 || HowMany>8) + return 0; + if (HowMany<=(Buffer_Size%8)) { Buffer_Size-=HowMany; @@ -117,6 +120,9 @@ class BitStream_Fast 0x1fff, 0x3fff, 0x7fff, 0xffff, }; + if (HowMany==0 || HowMany>16) + return 0; + if (HowMany<=(Buffer_Size%8)) { Buffer_Size-=HowMany; @@ -164,6 +170,9 @@ class BitStream_Fast 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff, }; + if (HowMany==0 || HowMany>32) + return 0; + if (HowMany<=(Buffer_Size%8)) { Buffer_Size-=HowMany; @@ -263,6 +272,9 @@ class BitStream_Fast 0x1f, 0x3f, 0x7f, 0xff, }; + if (HowMany==0 || HowMany>8) + return 0; + if (HowMany<=(Buffer_Size%8)) return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany]; @@ -295,6 +307,9 @@ class BitStream_Fast 0x1fff, 0x3fff, 0x7fff, 0xffff, }; + if (HowMany==0 || HowMany>16) + return 0; + if (HowMany<=(Buffer_Size%8)) return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany]; @@ -341,6 +356,9 @@ class BitStream_Fast 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff, }; + if (HowMany==0 || HowMany>32) + return 0; + if (HowMany<=(Buffer_Size%8)) return (LastByte>>((Buffer_Size-HowMany)%8))&Mask[HowMany]; diff --git a/Source/ZenLib/BitStream_LE.h b/Source/ZenLib/BitStream_LE.h index 20147c0..ac209f3 100644 --- a/Source/ZenLib/BitStream_LE.h +++ b/Source/ZenLib/BitStream_LE.h @@ -51,8 +51,6 @@ class BitStream_LE : public BitStream int32u Get (size_t HowMany) { - ptr_BeforeLastCall=ptr; - long ret; static const int32u Mask[33]={ 0x00000000, @@ -65,6 +63,12 @@ class BitStream_LE : public BitStream 0x01ffffff, 0x03ffffff, 0x07ffffff, 0x0fffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, 0xffffffff, }; + + if (HowMany==0 || HowMany>32) + return 0; + + ptr_BeforeLastCall=ptr; + unsigned long m=Mask[HowMany]; HowMany+=endbit; @@ -103,6 +107,20 @@ class BitStream_LE : public BitStream void Skip(size_t bits) { + if (bits==0) + return; + if (bits>32) //Get is only for <=32 bits + { + do { + Get(32); + if (!buffer) + return; + bits-=32; + } while (bits>32); + if (bits) + Get(bits); + return; + } Get(bits); } @@ -114,7 +132,7 @@ class BitStream_LE : public BitStream void Byte_Align() { if (endbit) - Get(endbit); + Get(8-endbit); }; size_t Offset_Get()