@@ -208,8 +208,17 @@ internal class CborParser(private val input: ByteArrayInput, private val verifyO
208
208
skipByte(unboundedHeader)
209
209
return - 1
210
210
}
211
- if ((curByte and 0b111_00000 ) != boundedHeaderMask)
211
+ if ((curByte and 0b111_00000 ) != boundedHeaderMask) {
212
+ if (boundedHeaderMask == HEADER_ARRAY && (curByte and 0b111_00000 ) == HEADER_BYTE_STRING ) {
213
+ throw CborDecodingException (
214
+ " Expected a start of array, " +
215
+ " but found ${printByte(curByte)} , which corresponds to the start of a byte string. " +
216
+ " Make sure you correctly set 'alwaysUseByteString' setting " +
217
+ " and/or 'kotlinx.serialization.cbor.ByteString' annotation."
218
+ )
219
+ }
212
220
throw CborDecodingException (" start of $collectionType " , curByte)
221
+ }
213
222
val size = readNumber().toInt()
214
223
readByte()
215
224
return size
@@ -221,8 +230,17 @@ internal class CborParser(private val input: ByteArrayInput, private val verifyO
221
230
222
231
fun nextByteString (tags : ULongArray? = null): ByteArray {
223
232
processTags(tags)
224
- if ((curByte and 0b111_00000 ) != HEADER_BYTE_STRING )
233
+ if ((curByte and 0b111_00000 ) != HEADER_BYTE_STRING ) {
234
+ if (curByte and 0b111_00000 == HEADER_ARRAY ) {
235
+ throw CborDecodingException (
236
+ " Expected a start of a byte string, " +
237
+ " but found ${printByte(curByte)} , which corresponds to the start of an array. " +
238
+ " Make sure you correctly set 'alwaysUseByteString' setting " +
239
+ " and/or 'kotlinx.serialization.cbor.ByteString' annotation."
240
+ )
241
+ }
225
242
throw CborDecodingException (" start of byte string" , curByte)
243
+ }
226
244
val arr = readBytes()
227
245
readByte()
228
246
return arr
0 commit comments