fix: use variable length encoding instead short for offsets (can overflow) (#1489)

This commit is contained in:
Skylot
2022-05-22 14:21:25 +01:00
parent e07332d49a
commit 6448f0e32b
10 changed files with 130 additions and 49 deletions
@@ -0,0 +1,40 @@
package jadx.gui.utils.codecache.disk.adapters;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class DataAdapterHelperTest {
@Test
void uvInt() throws IOException {
checkUVIntFor(0);
checkUVIntFor(7);
checkUVIntFor(0x7f);
checkUVIntFor(0x80);
checkUVIntFor(0x256);
checkUVIntFor(Byte.MAX_VALUE);
checkUVIntFor(Short.MAX_VALUE);
checkUVIntFor(Integer.MAX_VALUE);
}
private void checkUVIntFor(int val) throws IOException {
assertThat(writeReadUVInt(val)).isEqualTo(val);
}
private int writeReadUVInt(int val) throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
DataAdapterHelper.writeUVInt(out, val);
DataInput in = new DataInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
return DataAdapterHelper.readUVInt(in);
}
}