1 package org.simantics.databoard.tests;
3 import java.io.IOException;
7 import junit.framework.Assert;
10 import org.simantics.databoard.Bindings;
11 import org.simantics.databoard.binding.Binding;
12 import org.simantics.databoard.serialization.Serializer;
16 * @author Toni Kalajainen <toni.kalajainen@iki.fi>
18 public class TestMaliciousData {
20 public @Test void testArray() throws Exception {
23 Binding b = Bindings.getBinding(List.class, Integer.class);
24 Serializer s = Bindings.getSerializer(b);
26 // negative array length
28 byte[] data = new byte[] {-1, -1, -1, -1, 0, 1, 2, 3, 4};
30 Assert.fail("Deserialization did not fail expectedly on negative length array");
31 } catch (IOException e) {
37 byte[] data = new byte[] {10, 10, 10, 10, 0, 1, 2, 3, 4};
39 Assert.fail("Deserialization did not fail expectedly on too long array");
40 } catch (IOException e) {
46 byte[] data = new byte[] {0, 0, 0, 1, 0, 1, 2, 3};
48 } catch (IOException e) {
49 Assert.fail("Deserialization did not work");
54 public @Test void testBooleanArray() throws Exception {
57 Binding b = Bindings.BOOLEAN_ARRAY;
58 Serializer s = Bindings.getSerializer(b);
60 // negative array length
62 byte[] data = new byte[] {-1, -1, -1, -1, 0, 1, 2, 3, 4};
64 Assert.fail("Deserialization did not fail expectedly on negative length array");
65 } catch (IOException e) {
71 byte[] data = new byte[] {10, 10, 10, 10, 0, 1, 2, 3, 4};
73 Assert.fail("Deserialization did not fail expectedly on too long array");
74 } catch (IOException e) {
80 byte[] data = new byte[] {0, 0, 0, 1, 1};
82 } catch (IOException e) {
83 Assert.fail("Deserialization did not work");
88 public @Test void testMap() throws Exception {
91 Binding b = Bindings.getBinding(Map.class, Integer.class, Integer.class);
92 Serializer s = Bindings.getSerializer(b);
94 // negative array length
96 byte[] data = new byte[] {-1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7};
98 Assert.fail("Deserialization did not fail expectedly on negative length array");
99 } catch (IOException e) {
100 // Expected exception
105 byte[] data = new byte[] {10, 10, 10, 10, 0, 1, 2, 3, 4};
107 Assert.fail("Deserialization did not fail expectedly on too long array");
108 } catch (IOException e) {
109 // Expected exception
114 byte[] data = new byte[] {0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0};
116 } catch (IOException e) {
117 Assert.fail("Deserialization did not work");