fix: encryption system crashes and data corruption when ENABLE_ENCRYPTION=1#1684
fix: encryption system crashes and data corruption when ENABLE_ENCRYPTION=1#1684Kizuno18 wants to merge 1 commit intoopentibiabr:mainfrom
Conversation
…TION=1 Three bugs in the encryption system that make ENABLE_ENCRYPTION=1 unusable: 1. readFileContents() crashes on startup — accesses g_game.getFeature() which runs during g_resources.init(), before g_game is constructed. Removed the g_game dependency and the bot script feature gate (unrelated to encryption). Non-encrypted files now pass through instead of returning empty string, which also broke reading configs, .dat, .spr, etc. 2. writeFileContents() encrypts ALL file writes including user configs (config.otml, hotkeys, etc.), corrupting them on subsequent reads when the client restarts without encryption. Only the --encrypt builder should encrypt; runtime writes must remain plaintext. 3. FileStream::cache() decrypts unconditionally even when the file has no encryption header, causing garbage output. Also used std::memcmp instead of std::memcpy to copy decrypted data (compares but never copies), and resized the buffer incorrectly when no header was present. 4. logger.cpp silences ALL log output when ENABLE_ENCRYPTION=1, making debugging impossible. Removed the conditional — logging should work regardless of encryption state.
📝 WalkthroughWalkthroughThis PR simplifies encryption handling across the framework core by refactoring the Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
g_game.getFeature()beforeg_gameis constructed — removed the dependency; non-encrypted files now pass through instead of returning empty string--encryptbuilder should encryptstd::memcmpinstead ofstd::memcpy— now only decrypts when header is present, using in-place decryptTest plan
ENABLE_ENCRYPTION=0— no behavior changeENABLE_ENCRYPTION=1+ENABLE_ENCRYPTION_BUILDER=1, run--encrypton a copy ofdata/,modules/,mods/,init.luaENABLE_ENCRYPTION=1+ENABLE_ENCRYPTION_BUILDER=0(final exe)