@@ -491,6 +491,63 @@ TEST(project_name_encodes_unicode_segments_issue571) {
491491 PASS ();
492492}
493493
494+ /* issue #624: #571 preserves non-ASCII path segments by hex-encoding each byte
495+ * (1 byte -> 2 hex chars), so a DEEP non-ASCII path triples in length and can
496+ * blow past the filesystem's 255-byte filename-component limit. Then
497+ * "<cache>/<name>.db" is un-openable (ENAMETOOLONG). The derived name must be
498+ * length-capped (with a hash suffix that disambiguates otherwise-identical
499+ * prefixes) while staying validator-safe — and SHORT names must NOT drift. */
500+ #define FQN_CAP_UNDER_TEST 200
501+ TEST (project_name_length_capped_issue624 ) {
502+ /* 开 = U+5F00, UTF-8 "\xe5\xbc\x80" (3 bytes -> 6 hex chars). 60 copies makes
503+ * the raw hex-encoded name ~360 chars, well past the 200-byte cap. */
504+ static const char KAI [] = "\xe5\xbc\x80" ;
505+ char deepA [512 ];
506+ char deepB [512 ];
507+ const char * prefix = "/Users/dev/" ;
508+ size_t p = strlen (prefix );
509+ memcpy (deepA , prefix , p );
510+ for (int i = 0 ; i < 60 ; i ++ ) {
511+ memcpy (deepA + p , KAI , 3 );
512+ p += 3 ;
513+ }
514+ /* deepB shares the entire deep prefix and differs ONLY in the trailing seg */
515+ memcpy (deepB , deepA , p );
516+ memcpy (deepA + p , "/alpha" , 7 ); /* includes NUL */
517+ memcpy (deepB + p , "/omega" , 7 );
518+
519+ char * nameA = cbm_project_name_from_path (deepA );
520+ char * nameB = cbm_project_name_from_path (deepB );
521+ ASSERT_NOT_NULL (nameA );
522+ ASSERT_NOT_NULL (nameB );
523+
524+ /* (a) capped: name must fit within the filename-component budget */
525+ ASSERT_LTE (strlen (nameA ), FQN_CAP_UNDER_TEST );
526+ ASSERT_LTE (strlen (nameB ), FQN_CAP_UNDER_TEST );
527+ /* (b) still a valid project name (resolve_store must accept it) */
528+ ASSERT_TRUE (cbm_validate_project_name (nameA ));
529+ ASSERT_TRUE (cbm_validate_project_name (nameB ));
530+ /* (c) two deep paths differing only in the trailing segment must NOT
531+ * collide after capping — the hash suffix disambiguates them. */
532+ ASSERT_STR_NEQ (nameA , nameB );
533+
534+ free (nameA );
535+ free (nameB );
536+
537+ /* Short CJK path (the issue #571 case) must be UNCHANGED — no drift. */
538+ char * shortName = cbm_project_name_from_path (
539+ "/Users/yunxin/Desktop/\xe5\xbc\x80\xe5\x8f\x91/"
540+ "\xe5\x90\x8e\xe7\xab\xaf/"
541+ "\xe4\xbf\xa1\xe7\xa7\x9f\xe9\xa3\x8e\xe6\x8e\xa7\xe9\x80\x9a\xe5\x90\x8e\xe7\xab\xaf" );
542+ ASSERT_NOT_NULL (shortName );
543+ ASSERT_LTE (strlen (shortName ), FQN_CAP_UNDER_TEST );
544+ ASSERT_STR_EQ (shortName , "Users-yunxin-Desktop-e5bc80e58f91-e5908ee7abaf-"
545+ "e4bfa1e7a79fe9a38ee68ea7e9809ae5908ee7abaf" );
546+ free (shortName );
547+
548+ PASS ();
549+ }
550+
494551/* ================================================================
495552 * Suite
496553 * ================================================================ */
@@ -593,6 +650,7 @@ SUITE(fqn) {
593650 RUN_TEST (project_name_deep_path );
594651 RUN_TEST (project_name_always_validator_safe_issue349 );
595652 RUN_TEST (project_name_encodes_unicode_segments_issue571 );
653+ RUN_TEST (project_name_length_capped_issue624 );
596654 RUN_TEST (project_name_colon_only );
597655 RUN_TEST (project_name_backslash_only );
598656 RUN_TEST (project_name_consecutive_colons );
0 commit comments