Let C be a Brill-Noether-Petri curve of genus g\geq 12. We prove that C lies on a polarized K3 surface, or on a limit thereof, if and only if the Gauss-Wahl map for C is not surjective. The proof is obtained by studying the validity of two conjectures by J. Wahl. Let I_C be the ideal sheaf of a non-hyperelliptic, genus g, canonical curve. The first conjecture states that, if g\geq 8, and if the Clifford index of C is greater than 2, then H^1(P^{g-1}, I_C^2(k))=0, for k\geq 3. We prove this conjecture for g\geq 11. The second conjecture states that a Brill-Noether-Petri curve of genus g\geq 12 is extendable if and only if C lies on a K3 surface. As observed in the Introduction, the correct version of this conjecture should admit limits of polarised K3 surfaces in its statement. This is what we prove in the present work.