@@ -124,16 +124,24 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
124
124
125
125
break ;
126
126
}
127
- case TransferSession::OutputEventType::kQueryReceived : {
127
+ case TransferSession::OutputEventType::kQueryReceived :
128
+ case TransferSession::OutputEventType::kQueryWithSkipReceived : {
128
129
TransferSession::BlockData blockData;
129
130
uint16_t blockSize = mTransfer .GetTransferBlockSize ();
130
131
uint16_t bytesToRead = blockSize;
132
+ uint64_t bytesToSkip = 0 ;
133
+
134
+ if (event.EventType == TransferSession::OutputEventType::kQueryWithSkipReceived )
135
+ {
136
+ bytesToSkip = event.bytesToSkip .BytesToSkip ;
137
+ }
138
+ uint64_t seekOffset = mNumBytesSent + bytesToSkip;
131
139
132
140
// TODO: This should be a utility function in TransferSession
133
- if (mTransfer .GetTransferLength () > 0 && mNumBytesSent + blockSize > mTransfer .GetTransferLength ())
141
+ if (( mTransfer .GetTransferLength () > 0 ) && ((seekOffset + blockSize) > mTransfer .GetTransferLength () ))
134
142
{
135
143
// cast should be safe because of condition above
136
- bytesToRead = static_cast <uint16_t >(mTransfer .GetTransferLength () - mNumBytesSent );
144
+ bytesToRead = static_cast <uint16_t >(mTransfer .GetTransferLength () - seekOffset );
137
145
}
138
146
139
147
chip::System::PacketBufferHandle blockBuf = chip::System::PacketBufferHandle::New (bytesToRead);
@@ -152,7 +160,13 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
152
160
return ;
153
161
}
154
162
155
- otaFile.seekg (mNumBytesSent );
163
+ if (seekOffset > static_cast <uint64_t >(std::numeric_limits<std::streamoff>::max ()))
164
+ {
165
+ ChipLogError (BDX, " Seek offset too large" );
166
+ mTransfer .AbortTransfer (StatusCode::kLengthTooLarge );
167
+ return ;
168
+ }
169
+ otaFile.seekg (static_cast <std::streamoff>(seekOffset));
156
170
otaFile.read (reinterpret_cast <char *>(blockBuf->Start ()), bytesToRead);
157
171
if (!(otaFile.good () || otaFile.eof ()))
158
172
{
@@ -164,8 +178,8 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
164
178
blockData.Data = blockBuf->Start ();
165
179
blockData.Length = static_cast <size_t >(otaFile.gcount ());
166
180
blockData.IsEof = (blockData.Length < blockSize) ||
167
- (mNumBytesSent + static_cast <uint64_t >(blockData.Length ) == mTransfer .GetTransferLength () || (otaFile.peek () == EOF));
168
- mNumBytesSent = static_cast <uint32_t >(mNumBytesSent + blockData.Length );
181
+ (seekOffset + static_cast <uint64_t >(blockData.Length ) == mTransfer .GetTransferLength () || (otaFile.peek () == EOF));
182
+ mNumBytesSent = static_cast <uint32_t >(seekOffset + blockData.Length );
169
183
otaFile.close ();
170
184
171
185
err = mTransfer .PrepareBlock (blockData);
0 commit comments