henrylhtsang opened a new pull request, #419:
URL: https://github.com/apache/tvm-ffi/pull/419

   Fixes https://github.com/apache/tvm-ffi/issues/413
   
   ### Changes                                                                  
                                                                       
     1. **string.h**: Guard `std::memcpy` call with size check to avoid passing 
null source pointer with size 0                                                 
                                                                                
                                    
     2. **object.h**: Replace null pointer member access with standard 
`offsetof` macro for computing object header offsets             
   
   I tested manually for clang and gcc. Didn't test locally for msvc since I 
don't have access to windows. CI should test that.
   
   script:
   ```
   #include <tvm/ffi/string.h>
   #include <tvm/ffi/object.h>
   #include <iostream>
   
   class TestObj : public tvm::ffi::Object {
     public:
     static constexpr const char* _type_key = "test.TestObj";
   };
   
   int main() {
     std::cout << "Test 1: Creating string from null TVMFFIByteArray...\n";
     TVMFFIByteArray null_bytes{nullptr, 0};
     tvm::ffi::String str_from_null(null_bytes);
     std::cout << "String size: " << str_from_null.size() << "\n";
   
     std::cout << "Test 2: Computing object offset...\n";
     int64_t offset = 
tvm::ffi::details::ObjectUnsafe::GetObjectOffsetToSubclass<TestObj>();
     std::cout << "Offset: " << offset << "\n";
   
     std::cout << "Done - no UBSan errors!\n";
     return 0;
   }
   ```
   
   commands:
   ```
   cd ~/tvm-ffi
   git submodule update --init --recursive
   
   clang++ -std=c++17 -fsanitize=undefined -I./include 
-I./3rdparty/dlpack/include -x c++  repro.cpp  -o repro
   
   g++ -std=c++17 -fsanitize=undefined -I./include -I./3rdparty/dlpack/include 
repro.cpp -o repro
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to