forked from RuedigerMoeller/fast-serialization
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for objects that align poorly with FSTInt2ObjectMap
- Loading branch information
Carter Kozak
committed
Oct 9, 2017
1 parent
7a47c7d
commit c7fab67
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ser; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.nustaq.serialization.FSTConfiguration; | ||
import org.nustaq.serialization.FSTObjectInput; | ||
import org.nustaq.serialization.FSTObjectOutput; | ||
|
||
public class OverflowTest { | ||
|
||
@Test | ||
@Ignore | ||
public void test() throws Throwable { | ||
FSTConfiguration fc = FSTConfiguration.createDefaultConfiguration(); | ||
|
||
byte[] b; | ||
int len; | ||
try (FSTObjectOutput foo = new FSTObjectOutput(fc)) { | ||
foo.writeObject(new Outer()); | ||
b = foo.getBuffer(); | ||
len = foo.getWritten(); | ||
} | ||
ByteArrayInputStream bais = new ByteArrayInputStream(b, 0, len); | ||
FSTObjectInput foi = fc.getObjectInput(bais); | ||
foi.readObject(); | ||
} | ||
|
||
// Up to about stream offset 16K there is this other table. This needs to | ||
// be big enough to break past that and also produce enough stack frames to | ||
// overflow. | ||
private static final int OUTER_CT = 30000; | ||
|
||
public static class Outer implements Externalizable { | ||
@Override | ||
public void writeExternal(ObjectOutput out) throws IOException { | ||
for (int i = 0; i < OUTER_CT; ++i) { | ||
out.writeObject(new Inner()); | ||
} | ||
} | ||
|
||
@Override | ||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
for (int i = 0; i < OUTER_CT; ++i) { | ||
in.readObject(); | ||
} | ||
} | ||
} | ||
|
||
public static class Inner implements Externalizable { | ||
@Override | ||
public void writeExternal(ObjectOutput out) throws IOException { | ||
// An array of length 0 produces a period of 7 and we want to | ||
// target 23 which is the hash table size as picked up in the | ||
// debugger | ||
out.writeObject(new byte[16]); | ||
} | ||
|
||
@Override | ||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
in.readObject(); | ||
} | ||
} | ||
} |