From 8a45cb1d2030b4dfd6ff918fc251e12eb0f10445 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 12 Jul 2018 16:52:08 +0200 Subject: [PATCH] Prevent too long identifier names Signed-off-by: Joas Schilling --- lib/private/DB/MigrationService.php | 42 ++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 6f5a74103a5..b2ec3c13ba1 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -23,6 +23,7 @@ namespace OC\DB; +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaException; use OC\IntegrityCheck\Helpers\AppLocator; use OC\Migration\SimpleOutput; @@ -450,7 +451,9 @@ class MigrationService { }, ['tablePrefix' => $this->connection->getPrefix()]); if ($toSchema instanceof SchemaWrapper) { - $this->connection->migrateToSchema($toSchema->getWrappedSchema()); + $targetSchema = $toSchema->getWrappedSchema(); + $this->ensureOracleIdentifierLengthLimit($targetSchema); + $this->connection->migrateToSchema($targetSchema); $toSchema->performDropTableCalls(); } @@ -463,6 +466,43 @@ class MigrationService { $this->markAsExecuted($version); } + public function ensureOracleIdentifierLengthLimit(Schema $schema) { + foreach ($schema->getTables() as $table) { + if (\strlen($table->getName()) > 30) { + throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.'); + } + + foreach ($table->getColumns() as $thing) { + if (\strlen($thing->getName()) > 30) { + throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); + } + } + + foreach ($table->getIndexes() as $thing) { + if (\strlen($thing->getName()) > 30) { + throw new \InvalidArgumentException('Index name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); + } + } + + foreach ($table->getForeignKeys() as $thing) { + if (\strlen($thing->getName()) > 30) { + throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); + } + } + + $thing = $table->getPrimaryKey(); + if ($thing && (\strlen($table->getName()) > 26 || \strlen($thing->getName()) > 30)) { + throw new \InvalidArgumentException('Primary index name on "' . $table->getName() . '" is too long.'); + } + } + + foreach ($schema->getSequences() as $sequence) { + if (\strlen($sequence->getName()) > 30) { + throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.'); + } + } + } + private function ensureMigrationsAreLoaded() { if (empty($this->migrations)) { $this->migrations = $this->findMigrations();