SciProgCentre / dataforge-core

A clean multi-platform re-implementation of dataforge concepts
Apache License 2.0
25 stars 3 forks source link

Bad offset calculation in Tagless Envelope #55

Closed Zelenyy closed 2 years ago

Zelenyy commented 4 years ago

If read Tagless Envelope from ByteArray (see code), wrong calculation offset for data location.

    fun load(name: String): Envelope? {
        val entry = zipFile.getEntry(name)
        if (entry == null || entry.isDirectory) {
            return null
        }
        val bytes = zipFile.getInputStream(entry).readAllBytes()
        val binary = bytes.asBinary()
        val text = bytes.inputStream().bufferedReader().readText() // Смотрю содержимое в дебагерре
        return formatPeeker(binary)?.let {
            val partialEnvelope = binary.read {
                it.run { readPartial() }
            }
            val offset: Int = partialEnvelope.dataOffset.toInt()
            val size: Int = partialEnvelope.dataSize?.toInt() ?: (binary.size.toInt() - offset)
            val cut_bytes = bytes.sliceArray(offset..(offset+size-1))
            val text1 = cut_bytes.inputStream().bufferedReader().readText() // Смотрю содержимое в дебагерре
            SimpleEnvelope(partialEnvelope.meta, cut_bytes.asBinary())
        }
    }
Zelenyy commented 4 years ago

Probability, ignored size of "\r\n" separator.

altavir commented 4 years ago

thanks. I will check that.

altavir commented 2 years ago

Seems to be working properly for now. Will reopen if problem reappears.