| 1723 | // |
| 1724 | |
| 1725 | static int rleUncompress(int inLength, int maxLength, const signed char in[], |
| 1726 | char out[]) { |
| 1727 | char *outStart = out; |
| 1728 | |
| 1729 | while (inLength > 0) { |
| 1730 | if (*in < 0) { |
| 1731 | int count = -(static_cast<int>(*in++)); |
| 1732 | inLength -= count + 1; |
| 1733 | |
| 1734 | // Fixes #116: Add bounds check to in buffer. |
| 1735 | if ((0 > (maxLength -= count)) || (inLength < 0)) return 0; |
| 1736 | |
| 1737 | memcpy(out, in, count); |
| 1738 | out += count; |
| 1739 | in += count; |
| 1740 | } else { |
| 1741 | int count = *in++; |
| 1742 | inLength -= 2; |
| 1743 | |
| 1744 | if ((0 > (maxLength -= count + 1)) || (inLength < 0)) return 0; |
| 1745 | |
| 1746 | memset(out, *reinterpret_cast<const char *>(in), count + 1); |
| 1747 | out += count + 1; |
| 1748 | |
| 1749 | in++; |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | return static_cast<int>(out - outStart); |
| 1754 | } |
| 1755 | |
| 1756 | #ifdef __clang__ |
| 1757 | #pragma clang diagnostic pop |