Lets call the bitcoin address-hash AH(z) = RIPEMD160(SHA256(Q)) where Q is a public key or more generally a bitcoin script.
This is because I can use the birthday attack to search for strings s="SIG(A) and y=H(x)" and s'="SIG(B)" such that AH(s)==AH(s'). That can be done in work O(2^80) (and massive storage), or various time memory tradeoffs with lower storage and more work.
One work-around is to use scripts directly serialised into the transaction rather than script hash, however that impacts UTXO size, P2SH is good because only the script hash goes on the blockchain which is typically smaller than the script itself. Note script addresses are intentionally incompatible (different version) with regular addresses, so its not possible to find AH(Q)==AH(script) where Q is a public key and script is a script.
Probably the most generic approach is to increase the script hash address to 256-bit hash eg define new AH'(z) = SHA256( SHA256( z ) ).
Alternatively work-arounds or security can be achieved by considering the size of the attack O(2^80) + TMTO is large even relating to a bitcoin hashrate. Users of hashlock as a protocol sub-step should avoid creating pre-computation attacks. Eg accept hashlocks only on strings they had input in shortly-before (few hours/days which might be needed for confirmation) or during the protocol.
Adam
ps thanks to sipa and gmaxwell for discussion on IRC about this topic, clarifying assumptions for me.