From 7ce0be4bab846618729fae397e24348e638b6195 Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Thu, 6 Aug 2026 10:18:51 +0300 Subject: [PATCH] fix(PIBitArray): guard pop_back() against empty array pop_back() called resize(size_ - 1) without checking for empty. On empty array, uint underflow produced UINT_MAX, causing bytesInBits(UINT_MAX) overflow and subsequent OOB access. pop_front() already had this guard; pop_back() was missing it. --- libs/main/types/pibitarray.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/main/types/pibitarray.h b/libs/main/types/pibitarray.h index 4723e0ab..189e2067 100644 --- a/libs/main/types/pibitarray.h +++ b/libs/main/types/pibitarray.h @@ -5,7 +5,7 @@ //! \~russian Упакованный массив битов /* PIP - Platform Independent Primitives - Packed bit array + Packed bit array Ivan Pelipenko peri4ko@yandex.ru This program is free software: you can redistribute it and/or modify @@ -173,7 +173,10 @@ public: //! \~english Remove one bit from the end of array. //! \~russian Удаляет один бит с конца массива. - PIBitArray & pop_back() { return resize(size_ - 1); } + PIBitArray & pop_back() { + if (size_ == 0) return *this; + return resize(size_ - 1); + } //! \~english Remove one bit from the beginning of array. //! \~russian Удаляет один бит с начала массива.