Check-in [0e7a9af42e]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure the input byte array length matches the length in the class header.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0e7a9af42e2e25a56a0d0836afb762f4e12f2ba8
User & Date: stephanie.gawroriski 2019-04-17 16:22:39
Context
2019-04-17
16:29
Add end of file magic number and check that on read. check-in: bf36d53942 user: stephanie.gawroriski tags: trunk
16:22
Make sure the input byte array length matches the length in the class header. check-in: 0e7a9af42e user: stephanie.gawroriski tags: trunk
16:05
Do not debug add to pool. check-in: a4e744bc83 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/tool-classfile/dev/shadowtail/classfile/mini/MinimizedClassFile.java.

138
139
140
141
142
143
144






145
146
147
148
149
150
151
	{
		if (__is == null)
			throw new NullPointerException("NARG");
		
		// Read class header
		MinimizedClassHeader header = MinimizedClassHeader.decode(
			new ByteArrayInputStream(__is));






		
		// Read constant pool
		MinimizedPool pool = MinimizedPool.decode(header.poolcount,
			__is, header.pooloff, header.poolsize);
		
		// Read static and instance fields
		MinimizedField[] sfields = MinimizedField.decodeFields(







>
>
>
>
>
>







138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	{
		if (__is == null)
			throw new NullPointerException("NARG");
		
		// Read class header
		MinimizedClassHeader header = MinimizedClassHeader.decode(
			new ByteArrayInputStream(__is));
		
		// {@squirreljme.error JC45 Length of class file does not match
		// length of array. (The file length; The array length)}
		if (header.filesize != __is.length)
			throw new InvalidClassFormatException("JC45 " + header.filesize +
				" " + __is.length);
		
		// Read constant pool
		MinimizedPool pool = MinimizedPool.decode(header.poolcount,
			__is, header.pooloff, header.poolsize);
		
		// Read static and instance fields
		MinimizedField[] sfields = MinimizedField.decodeFields(

Changes to runt/libs/tool-classfile/dev/shadowtail/classfile/mini/MinimizedPool.java.

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137


138
139
140
141
142
143
144
			throw new IndexOutOfBoundsException("IOOB");
		
		// Types and offsets
		byte[] types = new byte[__n];
		int[] offsets = new int[__n];
		
		// Debug
		todo.DEBUG.note("Decode %d (%d bytes)", __n, __l);
		
		// Read the type and offset table
		try (DataInputStream dis = new DataInputStream(
			new ByteArrayInputStream(__is, __o, __l)))
		{
			// Read type table
			dis.readFully(types);
			
			// Skip padding?

			if ((__n & 1) != 0)
				dis.read();


			
			// Read offsets into the structure
			for (int i = 0; i < __n; i++)
				offsets[i] = dis.readUnsignedShort();
			
			// Debug
			for (int i = 0; i < __n; i++)







|








|
>

<
>
>







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145
146
			throw new IndexOutOfBoundsException("IOOB");
		
		// Types and offsets
		byte[] types = new byte[__n];
		int[] offsets = new int[__n];
		
		// Debug
		todo.DEBUG.note("Decode %d (%d bytes @ %d)", __n, __l, __o);
		
		// Read the type and offset table
		try (DataInputStream dis = new DataInputStream(
			new ByteArrayInputStream(__is, __o, __l)))
		{
			// Read type table
			dis.readFully(types);
			
			// {@squirreljme.error JC44 Pool uneven padding byte was not
			// 0xFF.}
			if ((__n & 1) != 0)

				if (dis.readUnsignedByte() != 0xFF)
					throw new InvalidClassFormatException("JC44");
			
			// Read offsets into the structure
			for (int i = 0; i < __n; i++)
				offsets[i] = dis.readUnsignedShort();
			
			// Debug
			for (int i = 0; i < __n; i++)