Skip to content

Commit

Permalink
check header sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
carterharrison committed Jan 18, 2019
1 parent 99fe9e5 commit f76ab04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ apply plugin: 'kotlin'
apply plugin: 'java'

group 'com.github.XYOracleNetwork'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ abstract class XyoIterableObject : XyoBuff() {
* @param offset The offset at which to read the header from.
*/
private fun getNextHeader (offset : Int) : XyoObjectSchema {
checkIndex(offset + 2)
return XyoObjectSchema.createFromHeader(item.copyOfRange(offset, offset + 2))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import network.xyo.sdkobjectmodelkotlin.exceptions.XyoObjectIteratorException
import network.xyo.sdkobjectmodelkotlin.objects.XyoIterableObject
import org.junit.Assert
import org.junit.Test
import java.math.BigInteger

class XyoObjectIteratorTest {

Expand Down Expand Up @@ -86,4 +87,18 @@ class XyoObjectIteratorTest {
throw Exception("Expected XyoObjectIteratorException to be thrown!")
} catch (e : XyoObjectIteratorException) { }
}

@Test
fun testCheckHeaderSize () {
try {
val iterator = object : XyoIterableObject() {
override val allowedOffset: Int = 0
override var item: ByteArray = BigInteger("601800526017004D201A49000B460000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040B030001030307", 16).toByteArray().copyOfRange(1, 84)
}.iterator

for (item in iterator) { }

throw Exception("Expected XyoObjectIteratorException to be thrown!")
} catch (e : XyoObjectIteratorException) { }
}
}

0 comments on commit f76ab04

Please sign in to comment.