Add asserts checking for negative container sizes (#14232)

Change-Id: I5b6298be367e4fe820320a5e3fd6bf5aaa7e2047