fix overflow on bounds checks

Closes #9020
use element count in slices, not size in bytes

This allows the indexing bounds check or other comparisons against an
element length to avoid a multiplication by the size.