@@ -293,6 +293,10 @@ double MyStringBuffer::getDouble() {
293293}
294294
295295char MyStringBuffer::getChar () {
296+ if (pos >= str.size ()) {
297+ throw IoTDBException (" MyStringBuffer::getChar: read past end (pos=" + std::to_string (pos) +
298+ " , size=" + std::to_string (str.size ()) + " )" );
299+ }
296300 return str[pos++];
297301}
298302
@@ -301,8 +305,16 @@ bool MyStringBuffer::getBool() {
301305}
302306
303307std::string MyStringBuffer::getString () {
304- size_t len = getInt ();
305- size_t tmpPos = pos;
308+ const int lenInt = getInt ();
309+ if (lenInt < 0 ) {
310+ throw IoTDBException (" MyStringBuffer::getString: negative length" );
311+ }
312+ const size_t len = static_cast <size_t >(lenInt);
313+ if (pos > str.size () || len > str.size () - pos) {
314+ throw IoTDBException (" MyStringBuffer::getString: length exceeds buffer (pos=" + std::to_string (pos) +
315+ " , len=" + std::to_string (len) + " , size=" + std::to_string (str.size ()) + " )" );
316+ }
317+ const size_t tmpPos = pos;
306318 pos += len;
307319 return str.substr (tmpPos, len);
308320}
@@ -351,6 +363,10 @@ void MyStringBuffer::checkBigEndian() {
351363}
352364
353365const char * MyStringBuffer::getOrderedByte (size_t len) {
366+ if (pos > str.size () || len > str.size () - pos) {
367+ throw IoTDBException (" MyStringBuffer::getOrderedByte: read past end (pos=" + std::to_string (pos) +
368+ " , len=" + std::to_string (len) + " , size=" + std::to_string (str.size ()) + " )" );
369+ }
354370 const char * p = nullptr ;
355371 if (isBigEndian) {
356372 p = str.c_str () + pos;
0 commit comments