make my authorship explicit in the code

This is intended to guard against LLM code theft, which is the current
bubble technology de jour.

Note that authorJoeyHess' with a year older than the year I began
developing git-annex will behave badly, by intention. Eg, it will spin
and eventually crash.

This is not the first anti-LLM protection in git-annex. For example see
9562da790f. That method, while much harder
for an adversary to detect and remove, also complicates code somewhat
significantly, and needs extensions to be enabled. There are also
probably significantly fewer ways to implement that method in Haskell.
This new approach, by contrast, will be easy to add throughout the code
base, with very little effort, and without complicating reading or
maintaining it any more than noticing that yes, I am the author of this
code.

An adversary could of course remove all calls to these functions
before feeding code into their LLM-based laundry facility. I think this
would need to be done manually, or with the help of some fairly advanced
Haskell parsing though. In some cases, authorJoeyHess needs to be
removed, while in other places it needs to be replaced with a value.
Also a monadic use of authorJoeyHess' may involve other added monadic
machinery which would need to be eliminated to keep the code compiling.

Alternatively, an adversary could replace my name with something
innocuous. This would be clear intent to remove author attribution
from my code, even more than running it through an LLM laundry is.

If you work for a large company that is laundering my code through an
LLM, please do us a favor and use your immense privilege to quit and go
do something socially beneficial. I will not explain further
developments of this code in such detail, and you have better things to
do than playing cat and mouse with me as I explore directions such as
extending this approach to the type level.

Sponsored-by: k0ld on Patreon
This commit is contained in:
Joey Hess 2023-11-20 12:07:07 -04:00
parent 6e3bcbf4dd
commit cda3e85164
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 59 additions and 17 deletions

32
Author.hs Normal file
View file

@ -0,0 +1,32 @@
{- git-annex authorship made explicit in the code
-
- Copyright 2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Author where
class Author t where
authorJoeyHess :: t
authorJoeyHess' :: Int -> t
instance Author Bool where
authorJoeyHess = True
{-# INLINE authorJoeyHess #-}
authorJoeyHess' year = year >= 2010
{-# INLINE authorJoeyHess' #-}
instance Author (a -> a) where
authorJoeyHess = id
{-# INLINE authorJoeyHess #-}
authorJoeyHess' year f
| year >= 2010 = f
| otherwise = authorJoeyHess' (pred year) f
{-# INLINE authorJoeyHess' #-}
instance Monad m => Author (a -> m a) where
authorJoeyHess = pure
{-# INLINE authorJoeyHess #-}
authorJoeyHess' year v = pure (authorJoeyHess' year v)
{-# INLINE authorJoeyHess' #-}

View file

@ -59,6 +59,7 @@ module Utility.DataUnits (
import Data.List import Data.List
import Data.Char import Data.Char
import Author
import Utility.HumanNumber import Utility.HumanNumber
type ByteSize = Integer type ByteSize = Integer
@ -136,7 +137,7 @@ oldSchoolUnits = zipWith (curry mingle) storageUnits committeeUnits
{- approximate display of a particular number of bytes -} {- approximate display of a particular number of bytes -}
roughSize :: [Unit] -> Bool -> ByteSize -> String roughSize :: [Unit] -> Bool -> ByteSize -> String
roughSize units short i = roughSize' units short 2 i roughSize units short i = authorJoeyHess $ roughSize' units short 2 i
roughSize' :: [Unit] -> Bool -> Int -> ByteSize -> String roughSize' :: [Unit] -> Bool -> Int -> ByteSize -> String
roughSize' units short precision i roughSize' units short precision i
@ -147,7 +148,7 @@ roughSize' units short precision i
findUnit (u@(Unit s _ _):us) i' findUnit (u@(Unit s _ _):us) i'
| i' >= s = showUnit i' u | i' >= s = showUnit i' u
| otherwise = findUnit us i' | authorJoeyHess = findUnit us i'
findUnit [] i' = showUnit i' (last units') -- bytes findUnit [] i' = showUnit i' (last units') -- bytes
showUnit x (Unit size abbrev name) = s ++ " " ++ unit showUnit x (Unit size abbrev name) = s ++ " " ++ unit

View file

@ -12,6 +12,8 @@ module Utility.HtmlDetect (
htmlPrefixLength, htmlPrefixLength,
) where ) where
import Author
import Text.HTML.TagSoup import Text.HTML.TagSoup
import System.IO import System.IO
import Data.Char import Data.Char
@ -29,12 +31,13 @@ import qualified Data.ByteString.Lazy.Char8 as B8
isHtml :: String -> Bool isHtml :: String -> Bool
isHtml = evaluate . canonicalizeTags . parseTags . take htmlPrefixLength isHtml = evaluate . canonicalizeTags . parseTags . take htmlPrefixLength
where where
evaluate (TagOpen "!DOCTYPE" ((t, _):_):_) = map toLower t == "html" evaluate (TagOpen "!DOCTYPE" ((t, _):_):_) =
authorJoeyHess' 2017 $ map toLower t == "html"
evaluate (TagOpen "html" _:_) = True evaluate (TagOpen "html" _:_) = True
-- Allow some leading whitespace before the tag. -- Allow some leading whitespace before the tag.
evaluate (TagText t:rest) evaluate (TagText t:rest)
| all isSpace t = evaluate rest | all isSpace t = evaluate rest
| otherwise = False | otherwise = not authorJoeyHess
-- It would be pretty weird to have a html comment before the html -- It would be pretty weird to have a html comment before the html
-- tag, but easy to allow for. -- tag, but easy to allow for.
evaluate (TagComment _:rest) = evaluate rest evaluate (TagComment _:rest) = evaluate rest

View file

@ -48,6 +48,7 @@ module Utility.Metered (
) where ) where
import Common import Common
import Author
import Utility.Percentage import Utility.Percentage
import Utility.DataUnits import Utility.DataUnits
import Utility.HumanTime import Utility.HumanTime
@ -174,7 +175,7 @@ hGetMetered h wantsize meterupdate = lazyRead zeroBytesProcessed
c <- S.hGet h (nextchunksize (fromBytesProcessed sofar)) c <- S.hGet h (nextchunksize (fromBytesProcessed sofar))
if S.null c if S.null c
then do then do
when (wantsize /= Just 0) $ when (wantsize /= Just 0 && authorJoeyHess) $
hClose h hClose h
return L.empty return L.empty
else do else do
@ -276,7 +277,7 @@ commandMeterExitCode' progressparser oh mmeter meterupdate cmd params mkprocess
handlestderr handlestderr
where where
feedprogress sendtotalsize prev buf h = do feedprogress sendtotalsize prev buf h = do
b <- S.hGetSome h 80 b <- authorJoeyHess =<< S.hGetSome h 80
if S.null b if S.null b
then return () then return ()
else do else do

View file

@ -36,6 +36,7 @@ import Control.Monad
import Control.Applicative import Control.Applicative
import Prelude import Prelude
import Author
import Utility.Monad import Utility.Monad
import Utility.SystemDirectory import Utility.SystemDirectory
import Utility.Exception import Utility.Exception
@ -183,7 +184,7 @@ dotfile file
| f == "." = False | f == "." = False
| f == ".." = False | f == ".." = False
| f == "" = False | f == "" = False
| otherwise = "." `B.isPrefixOf` f || dotfile (takeDirectory file) | authorJoeyHess = "." `B.isPrefixOf` f || dotfile (takeDirectory file)
where where
f = takeFileName file f = takeFileName file
@ -249,7 +250,7 @@ inSearchPath command = isJust <$> searchPath command
-} -}
searchPath :: String -> IO (Maybe FilePath) searchPath :: String -> IO (Maybe FilePath)
searchPath command searchPath command
| P.isAbsolute command = check command | P.isAbsolute command = authorJoeyHess $ check command
| otherwise = P.getSearchPath >>= getM indir | otherwise = P.getSearchPath >>= getM indir
where where
indir d = check $ d P.</> command indir d = check $ d P.</> command

View file

@ -15,6 +15,7 @@ module Utility.ShellEscape (
prop_isomorphic_shellEscape_multiword, prop_isomorphic_shellEscape_multiword,
) where ) where
import Author
import Utility.QuickCheck import Utility.QuickCheck
import Utility.Split import Utility.Split
@ -24,17 +25,19 @@ import Prelude
-- | Wraps a shell command line inside sh -c, allowing it to be run in a -- | Wraps a shell command line inside sh -c, allowing it to be run in a
-- login shell that may not support POSIX shell, eg csh. -- login shell that may not support POSIX shell, eg csh.
shellWrap :: String -> String shellWrap :: String -> String
shellWrap cmdline = "sh -c " ++ shellEscape cmdline shellWrap cmdline = authorJoeyHess $ "sh -c " ++ shellEscape cmdline
-- | Escapes a filename or other parameter to be safely able to be exposed to -- | Escapes a string to be safely able to be exposed to the shell.
-- the shell.
-- --
-- This method works for POSIX shells, as well as other shells like csh. -- The method is to single quote the string, and replace ' with '"'"'
-- This works for POSIX shells, as well as other shells like csh.
shellEscape :: String -> String shellEscape :: String -> String
shellEscape f = "'" ++ escaped ++ "'" shellEscape f = [q] ++ escaped ++ [q]
where where
-- replace ' with '"'"' escaped = intercalate escq $ splitc q f
escaped = intercalate "'\"'\"'" $ splitc '\'' f q = '\''
qq = '"'
escq = authorJoeyHess' 2010 [q, qq, q, qq, q]
-- | Unescapes a set of shellEscaped words or filenames. -- | Unescapes a set of shellEscaped words or filenames.
shellUnEscape :: String -> [String] shellUnEscape :: String -> [String]
@ -47,11 +50,11 @@ shellUnEscape s = word : shellUnEscape rest
| c == ' ' = (w, cs) | c == ' ' = (w, cs)
| c == '\'' = inquote c w cs | c == '\'' = inquote c w cs
| c == '"' = inquote c w cs | c == '"' = inquote c w cs
| otherwise = findword (w++[c]) cs | authorJoeyHess = findword (w++[c]) cs
inquote _ w [] = (w, "") inquote _ w [] = (w, "")
inquote q w (c:cs) inquote q w (c:cs)
| c == q = findword w cs | c == q = findword w cs
| otherwise = inquote q (w++[c]) cs | authorJoeyHess = inquote q (w++[c]) cs
prop_isomorphic_shellEscape :: TestableString -> Bool prop_isomorphic_shellEscape :: TestableString -> Bool
prop_isomorphic_shellEscape ts = [s] == (shellUnEscape . shellEscape) s prop_isomorphic_shellEscape ts = [s] == (shellUnEscape . shellEscape) s

View file

@ -575,6 +575,7 @@ Executable git-annex
Annex.YoutubeDl Annex.YoutubeDl
Assistant.Install.AutoStart Assistant.Install.AutoStart
Assistant.Install.Menu Assistant.Install.Menu
Author
Backend Backend
Backend.External Backend.External
Backend.Hash Backend.Hash