| 161 | TDecodedInput::~TDecodedInput() = default; |
| 162 | |
| 163 | size_t TDecodedInput::DoUnboundedNext(const void** ptr) { |
| 164 | if (!S_) { |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | TCodecID codecId; |
| 169 | TBlockLen blockLen; |
| 170 | |
| 171 | { |
| 172 | const size_t payload = sizeof(TCodecID) + sizeof(TBlockLen); |
| 173 | char buf[32]; |
| 174 | |
| 175 | S_->LoadOrFail(buf, payload); |
| 176 | |
| 177 | TMemoryInput in(buf, payload); |
| 178 | |
| 179 | ::Load(&in, codecId); |
| 180 | ::Load(&in, blockLen); |
| 181 | } |
| 182 | |
| 183 | if (!blockLen) { |
| 184 | S_ = nullptr; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | if (Y_UNLIKELY(blockLen > 1024 * 1024 * 1024)) { |
| 190 | ythrow yexception() << "block size exceeds 1 GiB"; |
| 191 | } |
| 192 | |
| 193 | TBuffer block; |
| 194 | block.Resize(blockLen); |
| 195 | |
| 196 | S_->LoadOrFail(block.Data(), blockLen); |
| 197 | |
| 198 | auto codec = CodecByID(codecId); |
| 199 | |
| 200 | if (C_) { |
| 201 | Y_ENSURE(C_->Name() == codec->Name(), TStringBuf("incorrect stream codec")); |
| 202 | } |
| 203 | |
| 204 | if (codec->DecompressedLength(block) > MAX_BUF_LEN) { |
| 205 | ythrow yexception() << "broken stream"; |
| 206 | } |
| 207 | |
| 208 | codec->Decode(block, D_); |
| 209 | *ptr = D_.Data(); |
| 210 | |
| 211 | return D_.Size(); |
| 212 | } |
nothing calls this directly
no test coverage detected