Browse Source

Fix ranges check in selfcheck iterator

Alexey Edelev 5 years ago
parent
commit
8d96349258
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/protobuf/qprotobufselfcheckiterator.h

+ 4 - 4
src/protobuf/qprotobufselfcheckiterator.h

@@ -46,7 +46,7 @@ public:
     QProtobufSelfcheckIterator(const QProtobufSelfcheckIterator &other) : m_sizeLeft(other.m_sizeLeft)
       , m_containerSize(other.m_containerSize)
       , m_it(other.m_it) {
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
     }
@@ -67,7 +67,7 @@ public:
 
     QProtobufSelfcheckIterator &operator --() {
         ++m_sizeLeft;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         --m_it;
@@ -85,7 +85,7 @@ public:
 
     QProtobufSelfcheckIterator &operator -=(int count) {
         m_sizeLeft += count;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         m_it -= count;
@@ -99,7 +99,7 @@ public:
 
         m_containerSize = other.m_containerSize;
         m_sizeLeft = other.m_sizeLeft;
-        if (m_sizeLeft >= m_containerSize) {
+        if (m_sizeLeft > m_containerSize || m_sizeLeft < 0) {
             throw std::out_of_range("Container is less than required fields number. Deserialization failed");
         }
         m_it = other.m_it;