797 static const uint8_t lengthbases[] =
798 { 0, 1, 2, 3, 4, 5, 6,
799 7, 8, 10, 12, 14, 16, 20,
800 24, 28, 32, 40, 48, 56, 64,
801 80, 96, 112, 128, 160, 192, 224 };
802 static const uint8_t lengthbits[] =
803 { 0, 0, 0, 0, 0, 0, 0,
806 4, 4, 4, 5, 5, 5, 5 };
807 static const int32_t offsetbases[] =
809 8, 12, 16, 24, 32, 48,
810 64, 96, 128, 192, 256, 384,
811 512, 768, 1024, 1536, 2048, 3072,
812 4096, 6144, 8192, 12288, 16384, 24576,
813 32768, 49152, 65536, 98304, 131072, 196608,
814 262144, 327680, 393216, 458752, 524288, 589824,
815 655360, 720896, 786432, 851968, 917504, 983040,
816 1048576, 1310720, 1572864, 1835008, 2097152, 2359296,
817 2621440, 2883584, 3145728, 3407872, 3670016, 3932160 };
818 static const uint8_t offsetbits[] =
819 { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4,
820 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10,
821 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16,
822 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
823 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 };
824 static const uint8_t shortbases[] =
825 { 0, 4, 8, 16, 32, 64, 128, 192 };
826 static const uint8_t shortbits[] =
827 { 2, 2, 3, 4, 5, 6, 6, 6 };
831 int symbol, offs, len, i;
879 else if (symbol <= 262) {
880 int idx = symbol - 259;
883 if (lensymbol < 0 || lensymbol > (
int)(
sizeof(lengthbases) /
sizeof(lengthbases[0])) || lensymbol > (
int)(
sizeof(lengthbits) /
sizeof(lengthbits[0]))) {
884 warn(
"Invalid data in bitstream");
887 len = lengthbases[lensymbol] + 2;
888 if (lengthbits[lensymbol] > 0) {
889 if (!
br_check(rar, lengthbits[lensymbol]))
891 len += (uint8_t)
br_bits(rar, lengthbits[lensymbol]);
893 for (i = idx; i > 0; i--)
897 else if (symbol <= 270) {
898 int idx = symbol - 263;
899 offs = shortbases[idx] + 1;
900 if (shortbits[idx] > 0) {
903 offs += (uint8_t)
br_bits(rar, shortbits[idx]);
906 for (i = 3; i > 0; i--)
911 int idx = symbol - 271;
913 if (idx > (
int)(
sizeof(lengthbases) /
sizeof(lengthbases[0])) || idx > (
int)(
sizeof(lengthbits) /
sizeof(lengthbits[0]))) {
914 warn(
"Invalid data in bitstream");
917 len = lengthbases[idx] + 3;
918 if (lengthbits[idx] > 0) {
919 if (!
br_check(rar, lengthbits[idx]))
921 len += (uint8_t)
br_bits(rar, lengthbits[idx]);
924 if (offssymbol < 0 || offssymbol > (
int)(
sizeof(offsetbases) /
sizeof(offsetbases[0])) || offssymbol > (
int)(
sizeof(offsetbits) /
sizeof(offsetbits[0]))) {
925 warn(
"Invalid data in bitstream");
928 offs = offsetbases[offssymbol] + 1;
929 if (offsetbits[offssymbol] > 0) {
930 if (offssymbol > 9) {
931 if (offsetbits[offssymbol] > 4) {
932 if (!
br_check(rar, offsetbits[offssymbol] - 4))
934 offs += (int)
br_bits(rar, offsetbits[offssymbol] - 4) << 4;
942 if (lowoffsetsymbol < 0)
944 if (lowoffsetsymbol == 16) {
949 offs += lowoffsetsymbol;
955 if (!
br_check(rar, offsetbits[offssymbol]))
957 offs += (int)
br_bits(rar, offsetbits[offssymbol]);
966 for (i = 3; i > 0; i--)