Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SHA*E backends: Exclude non-alphanumeric characters from extensions.

* SHA*E backends: Exclude non-alphanumeric characters from extensions.
* migrate: Remove leading \ in SHA* checksums, and non-alphanumerics
  from extensions of SHA*E keys.
  • Loading branch information...
commit bd0d06be239d778b72f237f34ca4ab36d568615e 1 parent e71f856
@joeyh authored
Showing with 16 additions and 6 deletions.
  1. +13 −5 Backend/SHA.hs
  2. +3 −1 debian/changelog
View
18 Backend/SHA.hs
@@ -17,6 +17,7 @@ import qualified Build.SysConfig as SysConfig
import Data.Digest.Pure.SHA
import qualified Data.ByteString.Lazy as L
import System.Process
+import Data.Char
type SHASize = Int
@@ -124,10 +125,8 @@ selectExtension f
where
es = filter (not . null) $ reverse $
take 2 $ takeWhile shortenough $
- reverse $ split "." $ takeExtensions f
- shortenough e
- | '\n' `elem` e = False -- newline in extension?!
- | otherwise = length e <= 4 -- long enough for "jpeg"
+ reverse $ split "." $ filter validExtension $ takeExtensions f
+ shortenough e = length e <= 4 -- long enough for "jpeg"
{- A key's checksum is checked during fsck. -}
checkKeyChecksum :: SHASize -> Key -> FilePath -> Annex Bool
@@ -152,5 +151,14 @@ checkKeyChecksum size key file = do
keySha :: Key -> String
keySha key = dropExtensions (keyName key)
+validExtension :: Char -> Bool
+validExtension c
+ | isAlphaNum c = True
+ | c == '.' = True
+ | otherwise = False
+
+{- Upgrade keys that have the \ prefix on their sha due to a bug, or
+ - that contain non-alphanumeric characters in their extension. -}
needsUpgrade :: Key -> Bool
-needsUpgrade key = "\\" `isPrefixOf` keySha key
+needsUpgrade key = "\\" `isPrefixOf` keySha key ||
+ any (not . validExtension) (takeExtensions $ keyName key)
View
4 debian/changelog
@@ -14,7 +14,9 @@ git-annex (3.20121212) UNRELEASED; urgency=low
when the filename contains \ or a newline. Closes: #696384
* fsck: Still accept checksums with a leading \ as valid, now that
above bug is fixed.
- * migrate: Remove leading \ in checksums.
+ * SHA*E backends: Exclude non-alphanumeric characters from extensions.
+ * migrate: Remove leading \ in SHA* checksums, and non-alphanumerics
+ from extensions of SHA*E keys.
-- Joey Hess <joeyh@debian.org> Thu, 13 Dec 2012 14:06:43 -0400
Please sign in to comment.
Something went wrong with that request. Please try again.