diff --git a/CHANGES b/CHANGES
index 917a2d48522bcb75d12360ebaa9cb10fb7c40c05..e4ba6f9f6300c371ff3eec8d59954cc3af27c6f3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,7 @@ OpenLDAP 2.4.11 Engineering
 	Fixed slapd crash with no listeners (ITS#5563)
 	Fixed slapd equality rules for olcRootDN/olcSchemaDN (ITS#5540)
 	Fixed slapd sets memory leak (ITS#5557)
+	Fixed slapd sortvals binary search (ITS#5578)
 	Fixed slapd/slapo-syncprov syncrepl contextCSN updates as internal ops (ITS#5596)
 	Fixed slapd-meta link to slapd-ldap (ITS#5355)
 	Fixed slapd-sock, back-shell buffer count (ITS#5558)
diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c
index e54ed671be4c0f7b8f3d300c4bbeb59fc50568d2..8204fa7be860406b9f16cc9505a7dff3506b9eb1 100644
--- a/servers/slapd/attr.c
+++ b/servers/slapd/attr.c
@@ -324,17 +324,16 @@ attr_valfind(
 		while ( 0 < n ) {
 			unsigned pivot = n >> 1;
 			i = base + pivot;
-			if ( i >= a->a_numvals ) {
-				i = a->a_numvals - 1;
-				break;
-			}
 			rc = value_match( &match, a->a_desc, mr, flags,
 				&a->a_nvals[i], cval, &text );
 			if ( rc == LDAP_SUCCESS && match == 0 )
 				break;
-			n = pivot;
-			if ( match < 0 )
+			if ( match < 0 ) {
 				base = i+1;
+				n -= pivot+1;
+			} else {
+				n = pivot;
+			}
 		}
 		if ( match < 0 )
 			i++;