From fbe37ea6d90f7bfe18506b042657c6e533eaf9b2 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 24 Apr 2023 12:43:48 -0400 Subject: Fix issue with Obfuscated hash (#2834) * #include an absolute path didn't work - because paths were taken to always be relative. * Remove legacy container writing. Test using module without source map. * Change hashing for obfuscated source map such that takes into account different line endings. --- source/slang/slang-ir-obfuscate-loc.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-ir-obfuscate-loc.cpp b/source/slang/slang-ir-obfuscate-loc.cpp index 7bb4bef7d..ecc16d2b2 100644 --- a/source/slang/slang-ir-obfuscate-loc.cpp +++ b/source/slang/slang-ir-obfuscate-loc.cpp @@ -130,9 +130,18 @@ SlangResult obfuscateModuleLocs(IRModule* module, SourceManager* sourceManager) hash = combineHash(hash, nameHash); } - // We combine the *offset* which is stable + // We *can't* just use the offset to produce the hash, because the source might have + // different line endings on different platforms (in particular linux/unix-like and windows). + // So we hash the line number/line offset to work around + const auto offset = sourceView->getRange().getOffset(curLoc); - hash = combineHash(hash, getHashCode(offset)); + + const auto sourceFile = sourceView->getSourceFile(); + const auto lineIndex = sourceFile->calcLineIndexFromOffset(offset); + const auto lineOffset = sourceFile->calcColumnOffset(lineIndex, offset); + + hash = combineHash(hash, getHashCode(lineIndex)); + hash = combineHash(hash, getHashCode(lineOffset)); } } } -- cgit v1.2.3