diff --git a/tsk/fs/tsk_apfs.hpp b/tsk/fs/tsk_apfs.hpp
index 27ec246bc9f5fa4ac1f86731a6c212072f9998fa..700cd54f07ef2569dda723fcf5c3393b07e36779 100755
--- a/tsk/fs/tsk_apfs.hpp
+++ b/tsk/fs/tsk_apfs.hpp
@@ -142,7 +142,7 @@ class APFSBtreeNodeIterator {
     const auto &t = _node->_table_data.toc.variable[_index];
     const auto key_data = _node->_table_data.koff + t.key_offset;
     const auto val_data = _node->_table_data.voff - t.val_offset;
-    if (key_data > _node->_storage.data()) {
+    if (key_data > _node->_storage.data() + _node->_storage.size()) {
       throw std::runtime_error("init_value: invalid key_offset");
     }
     if (val_data < _node->_storage.data()) {
@@ -174,7 +174,7 @@ class APFSBtreeNodeIterator {
     const auto &t = _node->_table_data.toc.fixed[_index];
     const auto key_data = _node->_table_data.koff + t.key_offset;
     const auto val_data = _node->_table_data.voff - t.val_offset;
-    if (key_data > _node->_storage.data()) {
+    if (key_data > _node->_storage.data() + _node->_storage.size()) {
       throw std::runtime_error("init_value: invalid key_offset");
     }
     if (val_data < _node->_storage.data()) {
@@ -1166,7 +1166,7 @@ inline void APFSBtreeNodeIterator<APFSJObjBtreeNode>::init_value<void>(int recur
   const auto &t = _node->_table_data.toc.variable[_index];
   const auto key_data = _node->_table_data.koff + t.key_offset;
   const auto val_data = _node->_table_data.voff - t.val_offset;
-  if (key_data > _node->_storage.data()) {
+  if (key_data > _node->_storage.data() + _node->_storage.size()) {
     throw std::runtime_error("APFSBtreeNodeIterator<APFSJObjBtreeNode>::init_value: invalid key_offset");
   }
   if (val_data < _node->_storage.data()) {