From 7f2cc546b74c390b5b21edb359c858749e1e89f8 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Mon, 17 Aug 2015 13:38:21 +0200 Subject: [PATCH 1/2] avoid overflow in vector_ref::cropped --- libdevcore/vector_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index b5d0453a6..432e61fac 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -61,7 +61,7 @@ public: /// @returns a new vector_ref which is a shifted and shortened view of the original data. /// If this goes out of bounds in any way, returns an empty vector_ref. /// If @a _count is ~size_t(0), extends the view to the end of the data. - vector_ref<_T> cropped(size_t _begin, size_t _count) const { if (m_data && _begin + _count <= m_count) return vector_ref<_T>(m_data + _begin, _count == ~size_t(0) ? m_count - _begin : _count); else return vector_ref<_T>(); } + vector_ref<_T> cropped(size_t _begin, size_t _count) const { if (m_data && _begin < m_count && _count <= m_count && _begin + _count <= m_count) return vector_ref<_T>(m_data + _begin, _count == ~size_t(0) ? m_count - _begin : _count); else return vector_ref<_T>(); } /// @returns a new vector_ref which is a shifted view of the original data (not going beyond it). vector_ref<_T> cropped(size_t _begin) const { if (m_data && _begin <= m_count) return vector_ref<_T>(m_data + _begin, m_count - _begin); else return vector_ref<_T>(); } void retarget(_T* _d, size_t _s) { m_data = _d; m_count = _s; } From ac2216aaf9ad8bee424f635bc0279742fe8315bc Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 19 Aug 2015 11:40:12 +0200 Subject: [PATCH 2/2] allow _begin == _count in vector_ref --- libdevcore/vector_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index 6102479f6..09a06df7f 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -55,7 +55,7 @@ public: /// @returns a new vector_ref which is a shifted and shortened view of the original data. /// If this goes out of bounds in any way, returns an empty vector_ref. /// If @a _count is ~size_t(0), extends the view to the end of the data. - vector_ref<_T> cropped(size_t _begin, size_t _count) const { if (m_data && _begin < m_count && _count <= m_count && _begin + _count <= m_count) return vector_ref<_T>(m_data + _begin, _count == ~size_t(0) ? m_count - _begin : _count); else return vector_ref<_T>(); } + vector_ref<_T> cropped(size_t _begin, size_t _count) const { if (m_data && _begin <= m_count && _count <= m_count && _begin + _count <= m_count) return vector_ref<_T>(m_data + _begin, _count == ~size_t(0) ? m_count - _begin : _count); else return vector_ref<_T>(); } /// @returns a new vector_ref which is a shifted view of the original data (not going beyond it). vector_ref<_T> cropped(size_t _begin) const { if (m_data && _begin <= m_count) return vector_ref<_T>(m_data + _begin, m_count - _begin); else return vector_ref<_T>(); } void retarget(_T* _d, size_t _s) { m_data = _d; m_count = _s; }