diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal
index 7bdfac8a14d77c600f67615a7e7465025c76494b..49366c5a1cade847171efe657530632e13ca5b60 100644
--- a/Cabal/Cabal.cabal
+++ b/Cabal/Cabal.cabal
@@ -35,6 +35,8 @@ extra-source-files:
   -- BEGIN gen-extra-source-files
   tests/ParserTests/errors/MiniAgda.cabal
   tests/ParserTests/errors/MiniAgda.errors
+  tests/ParserTests/errors/big-version.cabal
+  tests/ParserTests/errors/big-version.errors
   tests/ParserTests/errors/common1.cabal
   tests/ParserTests/errors/common1.errors
   tests/ParserTests/errors/common2.cabal
@@ -112,6 +114,9 @@ extra-source-files:
   tests/ParserTests/regressions/assoc-cpp-options.check
   tests/ParserTests/regressions/bad-glob-syntax.cabal
   tests/ParserTests/regressions/bad-glob-syntax.check
+  tests/ParserTests/regressions/big-version.cabal
+  tests/ParserTests/regressions/big-version.expr
+  tests/ParserTests/regressions/big-version.format
   tests/ParserTests/regressions/cc-options-with-optimization.cabal
   tests/ParserTests/regressions/cc-options-with-optimization.check
   tests/ParserTests/regressions/common-conditional.cabal
diff --git a/Cabal/Distribution/PackageDescription/Quirks.hs b/Cabal/Distribution/PackageDescription/Quirks.hs
index e00d1527010ba348c2697e15a9816b436d0b2ba2..d154d96e577bce3c509de075d5233a9e97c978ae 100644
--- a/Cabal/Distribution/PackageDescription/Quirks.hs
+++ b/Cabal/Distribution/PackageDescription/Quirks.hs
@@ -233,6 +233,24 @@ patches = Map.fromList
          (Fingerprint 12694656661460787751 1902242956706735615)
          (Fingerprint 15433152131513403849 2284712791516353264)
          (bsReplace "1.2.03.0" "1.2.3.0")
+    -- 9 digits limit
+    , mk "Name:                SGplus\nVersion:             1.1\nSynopsis:            (updated) Small geometry library for dealing with vectors and collision detection\nLicense:             BSD3\nLicense-file:        LICENSE\nAuthor:              Neil Brown\nMaintainer:  "
+         (Fingerprint 17735649550442248029 11493772714725351354)
+         (Fingerprint 9565458801063261772 15955773698774721052)
+         (bsReplace "1000000000" "100000000")
+    , mk "-- Initial control-dotdotdot.cabal generated by cabal init.  For further \n-- documentation, see http://haskell.org/cabal/users-guide/\n\nname:                control-dotdotdot\nversion:             0.1.0.1\nsynopsis:            Haskell operator\n               "
+         (Fingerprint 1514257173776509942 7756050823377346485)
+         (Fingerprint 14082092642045505999 18415918653404121035)
+         (bsReplace "9223372036854775807" "5")
+    , mk "name:                data-foldapp\r\nversion:             0.1.1.0\r\nsynopsis:            Fold function applications. Framework for variadic functions.\r\ndescription:         Fold function applications. Framework for variadic functions.\r\nhomepage:            ht"
+         (Fingerprint 4511234156311243251 11701153011544112556)
+         (Fingerprint 11820542702491924189 4902231447612406724)
+         (bsReplace "9223372036854775807" "999" . bsReplace "9223372036854775807" "999")
+    , mk "-- Initial data-list-zigzag.cabal generated by cabal init.  For further \r\n-- documentation, see http://haskell.org/cabal/users-guide/\r\n\r\nname:                data-list-zigzag\r\nversion:             0.1.1.1\r\nsynopsis:            A list but with a balanced en"
+         (Fingerprint 12475837388692175691 18053834261188158945)
+         (Fingerprint 16279938253437334942 15753349540193002309)
+         (bsReplace "9223372036854775807" "999")
+
     ]
   where
     mk a b c d = ((a, b), (c, d))
diff --git a/Cabal/Distribution/Types/Version.hs b/Cabal/Distribution/Types/Version.hs
index 57e057267545dd83b8de121c5c42ea3743abdc70..b4d4da35570c993d1b3aef8305b317eff7d63f81 100644
--- a/Cabal/Distribution/Types/Version.hs
+++ b/Cabal/Distribution/Types/Version.hs
@@ -109,7 +109,13 @@ versionDigitParser = (some d >>= toNumber) P.<?> "version digit (integral withou
     toNumber :: CabalParsing m => [Int] -> m Int
     toNumber [0]   = return 0
     toNumber (0:_) = P.unexpected "Version digit with leading zero"
-    toNumber xs    = return $ foldl' (\a b -> a * 10 + b) 0 xs
+    toNumber xs
+        -- 10^9 = 1000000000
+        -- 2^30 = 1073741824
+        --
+        -- GHC Int is at least 32 bits, so 2^31-1 is the 'maxBound'.
+        | length xs > 9 = P.unexpected "At most 9 numbers are allowed per version number part"
+        | otherwise     = return $ foldl' (\a b -> a * 10 + b) 0 xs
 
     d :: P.CharParsing m => m Int
     d = f <$> P.satisfyRange '0' '9'
diff --git a/Cabal/tests/ParserTests.hs b/Cabal/tests/ParserTests.hs
index e93108137d772ab8e1a2a0592b0a0d2416069253..82460e9ca5876968979dc33140098f6ecde78a37 100644
--- a/Cabal/tests/ParserTests.hs
+++ b/Cabal/tests/ParserTests.hs
@@ -124,6 +124,7 @@ errorTests = testGroup "errors"
     , errorTest "libpq1.cabal"
     , errorTest "libpq2.cabal"
     , errorTest "MiniAgda.cabal"
+    , errorTest "big-version.cabal"
     ]
 
 errorTest :: FilePath -> TestTree
@@ -181,6 +182,7 @@ regressionTests = testGroup "regressions"
     , regressionTest "indentation.cabal"
     , regressionTest "indentation2.cabal"
     , regressionTest "indentation3.cabal"
+    , regressionTest "big-version.cabal"
     ]
 
 regressionTest :: FilePath -> TestTree
diff --git a/Cabal/tests/ParserTests/errors/big-version.cabal b/Cabal/tests/ParserTests/errors/big-version.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..533dae563aa8ca2e8abb9622589eaf025e5fb0a4
--- /dev/null
+++ b/Cabal/tests/ParserTests/errors/big-version.cabal
@@ -0,0 +1,7 @@
+cabal-version:       3.0
+name:                big-vesion
+-- 10 digits
+version:             1234567890
+
+library
+  default-language: Haskell2010
diff --git a/Cabal/tests/ParserTests/errors/big-version.errors b/Cabal/tests/ParserTests/errors/big-version.errors
new file mode 100644
index 0000000000000000000000000000000000000000..b51efaaf466fd1c6414e96b285cbf157525a9f9e
--- /dev/null
+++ b/Cabal/tests/ParserTests/errors/big-version.errors
@@ -0,0 +1,4 @@
+VERSION: Just (mkVersion [3,0])
+big-version.cabal:4:32: 
+unexpected At most 9 numbers are allowed per version number part
+
diff --git a/Cabal/tests/ParserTests/regressions/big-version.cabal b/Cabal/tests/ParserTests/regressions/big-version.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..1812bdde664532e0d7e035a10969ec1178482580
--- /dev/null
+++ b/Cabal/tests/ParserTests/regressions/big-version.cabal
@@ -0,0 +1,7 @@
+cabal-version:       3.0
+name:                big-vesion
+-- 9 digits
+version:             123456789
+
+library
+  default-language: Haskell2010
diff --git a/Cabal/tests/ParserTests/regressions/big-version.expr b/Cabal/tests/ParserTests/regressions/big-version.expr
new file mode 100644
index 0000000000000000000000000000000000000000..0bfaeb4c370e379d20eee831c6b2021f14ce98ae
--- /dev/null
+++ b/Cabal/tests/ParserTests/regressions/big-version.expr
@@ -0,0 +1,95 @@
+GenericPackageDescription
+  {condBenchmarks = [],
+   condExecutables = [],
+   condForeignLibs = [],
+   condLibrary = Just
+                   CondNode
+                     {condTreeComponents = [],
+                      condTreeConstraints = [],
+                      condTreeData = Library
+                                       {exposedModules = [],
+                                        libBuildInfo = BuildInfo
+                                                         {asmOptions = [],
+                                                          asmSources = [],
+                                                          autogenIncludes = [],
+                                                          autogenModules = [],
+                                                          buildToolDepends = [],
+                                                          buildTools = [],
+                                                          buildable = True,
+                                                          cSources = [],
+                                                          ccOptions = [],
+                                                          cmmOptions = [],
+                                                          cmmSources = [],
+                                                          cppOptions = [],
+                                                          customFieldsBI = [],
+                                                          cxxOptions = [],
+                                                          cxxSources = [],
+                                                          defaultExtensions = [],
+                                                          defaultLanguage = Just Haskell2010,
+                                                          extraBundledLibs = [],
+                                                          extraDynLibFlavours = [],
+                                                          extraFrameworkDirs = [],
+                                                          extraGHCiLibs = [],
+                                                          extraLibDirs = [],
+                                                          extraLibFlavours = [],
+                                                          extraLibs = [],
+                                                          frameworks = [],
+                                                          hsSourceDirs = [],
+                                                          includeDirs = [],
+                                                          includes = [],
+                                                          installIncludes = [],
+                                                          jsSources = [],
+                                                          ldOptions = [],
+                                                          mixins = [],
+                                                          oldExtensions = [],
+                                                          options = PerCompilerFlavor [] [],
+                                                          otherExtensions = [],
+                                                          otherLanguages = [],
+                                                          otherModules = [],
+                                                          pkgconfigDepends = [],
+                                                          profOptions = PerCompilerFlavor [] [],
+                                                          sharedOptions = PerCompilerFlavor [] [],
+                                                          staticOptions = PerCompilerFlavor [] [],
+                                                          targetBuildDepends = [],
+                                                          virtualModules = []},
+                                        libExposed = True,
+                                        libName = LMainLibName,
+                                        libVisibility = LibraryVisibilityPublic,
+                                        reexportedModules = [],
+                                        signatures = []}},
+   condSubLibraries = [],
+   condTestSuites = [],
+   genPackageFlags = [],
+   packageDescription = PackageDescription
+                          {author = "",
+                           benchmarks = [],
+                           bugReports = "",
+                           buildTypeRaw = Nothing,
+                           category = "",
+                           copyright = "",
+                           customFieldsPD = [],
+                           dataDir = "",
+                           dataFiles = [],
+                           description = "",
+                           executables = [],
+                           extraDocFiles = [],
+                           extraSrcFiles = [],
+                           extraTmpFiles = [],
+                           foreignLibs = [],
+                           homepage = "",
+                           library = Nothing,
+                           licenseFiles = [],
+                           licenseRaw = Left NONE,
+                           maintainer = "",
+                           package = PackageIdentifier
+                                       {pkgName = `PackageName "big-vesion"`,
+                                        pkgVersion = `mkVersion [123456789]`},
+                           pkgUrl = "",
+                           setupBuildInfo = Nothing,
+                           sourceRepos = [],
+                           specVersionRaw = Left `mkVersion [3,0]`,
+                           stability = "",
+                           subLibraries = [],
+                           synopsis = "",
+                           testSuites = [],
+                           testedWith = []}}
diff --git a/Cabal/tests/ParserTests/regressions/big-version.format b/Cabal/tests/ParserTests/regressions/big-version.format
new file mode 100644
index 0000000000000000000000000000000000000000..c1e68ec0834286fbd5ca7b423d0e7824b67cf183
--- /dev/null
+++ b/Cabal/tests/ParserTests/regressions/big-version.format
@@ -0,0 +1,6 @@
+cabal-version: 3.0
+name:          big-vesion
+version:       123456789
+
+library
+    default-language: Haskell2010