diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
index cc97849..92cfcd2 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
@@ -136,6 +136,10 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa
   public function loadMultiple(array $ids = NULL) {
     $entities = array();
 
+    if ($ids !== NULL) {
+      $ids = $this->cleanIds($ids);
+    }
+
     // Create a new variable which is either a prepared version of the $ids
     // array for later comparison with the entity cache, or FALSE if no $ids
     // were passed. The $ids array is reduced as items are loaded from cache,
@@ -1455,4 +1459,33 @@ static public function _fieldColumnName(FieldConfigInterface $field, $column) {
     return in_array($column, FieldConfig::getReservedColumns()) ? $column : $field->getName() . '_' . $column;
   }
 
+  /**
+   * Verifies that the specified entity ids are of the correct data type for
+   * the entity type.
+   *
+   * @param array $ids
+   *   The entity ids to verify.
+   */
+  protected function cleanIds(array $ids) {
+    $entity_manager = \Drupal::entityManager();
+    $keys = $this->entityType->getKeys();
+    $bundle = $keys['bundle'] ? $keys['bundle'] : $this->entityTypeId;
+
+    $definitions = $entity_manager->getFieldDefinitions($this->entityTypeId, $bundle);
+    $info = $entity_manager->getDefinition($this->entityTypeId);
+    $id_definition = $definitions[$info->getKey('id')];
+
+    if ($id_definition->getType() == 'integer') {
+      foreach ($ids as $index => $id) {
+        if (!is_int($id)) {
+          if (ctype_digit($id)) {
+            $ids[$index] = intval($id);
+          } else {
+            unset($ids[$index]);
+          }
+        }
+      }
+    }
+    return $ids;
+  }
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundTest.php b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundTest.php
index b248ff7..b3d7a69 100644
--- a/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/System/PageNotFoundTest.php
@@ -35,6 +35,12 @@ function testPageNotFound() {
     $this->drupalGet($this->randomName(10));
     $this->assertText(t('Page not found'), 'Found the default 404 page');
 
+    // Test some invalid ids
+    $this->drupalGet('node/invalid');
+    $this->assertResponse(404);
+    $this->drupalGet('user/invalid');
+    $this->assertResponse(404);
+
     // Use a custom 404 page.
     $edit = array(
       'site_404' => 'user/' . $this->admin_user->id(),
