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