Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2810

misaligned address

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.12.0
    • Component/s: libbson, libmongoc
    • None
    • Environment:
      Ubuntu 18.04
      Clang 6.0.0
      libc++

      libasan build

      I updated the mongo-cxx-driver, mongo-c-driver and libbson (which is now part of mongo-c-driver) to the newest versions.

      The mongo-c-driver is now version 1.12 (changeset a690091bae086f267791bd2227400f2035de99e8).

      At our company, we use a self built toolchain:

      • Clang 6.0.0 with libc++

      We test our software with many sanitizers. UBSan is one of them. Since the update, I get the following error:

      /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-read-prefs.c:29:16: runtime error: member access within misaligned address 0x61300000ffc0 for type 'mongoc_read_prefs_t' (aka 'struct _mongoc_read_prefs_t'), which requires 128 byte alignment
      0x61300000ffc0: note: pointer points here
       0e 00 00 4a  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
                    ^ 
          #0 0xb644d52 in mongoc_read_prefs_new /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-read-prefs.c:29:16
          #1 0xb7b4e98 in mongoc_uri_new_with_error /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-uri.c:1443:22
          #2 0xb7b7f45 in mongoc_uri_new /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-uri.c:1493:10
          #3 0xb494873 in mongocxx::v_noabi::uri::uri(bsoncxx::v_noabi::string::view_or_value) /src/mongo-cxx-driver/src/mongocxx/uri.cpp:51:37
      ... more application specific backtraceSUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-read-prefs.c:29:16 in 
      /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-read-prefs.c:29:16: runtime error: store to misaligned address 0x61300000ffc0 for type 'mongoc_read_mode_t', which requires 128 byte alignment
      0x61300000ffc0: note: pointer points here
       0e 00 00 4a  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
                    ^ 
          #0 0xb644d86 in mongoc_read_prefs_new /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-read-prefs.c:29:21
          #1 0xb7b4e98 in mongoc_uri_new_with_error /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-uri.c:1443:22
          #2 0xb7b7f45 in mongoc_uri_new /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-uri.c:1493:10
          #3 0xb494873 in mongocxx::v_noabi::uri::uri(bsoncxx::v_noabi::string::view_or_value) /src/mongo-cxx-driver/src/mongocxx/uri.cpp:51:37
      ... more application specific backtrace
      SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-server-stream.c:48:57 in 
      /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-server-stream.c:49:37: runtime error: member access within misaligned address 0x6130000202c0 for type 'mongoc_server_stream_t' (aka 'struct _mongoc_server_stream_t'), which requires 128 byte alignment
      0x6130000202c0: note: pointer points here
       0a 00 00 30  04 00 00 00 be be be be  80 26 02 00 d0 61 00 00  be be be be be be be be  be be be be
                    ^ 
          #0 0xb74bd09 in mongoc_server_stream_cleanup /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-server-stream.c:49:37
          #1 0xb5de014 in _mongoc_cursor_run_command /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor.c:1017:4
          #2 0xb5e50f6 in _mongoc_cursor_response_refresh /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor.c:1582:8
          #3 0xb5eb5db in _prime /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor-find-cmd.c:36:4
          #4 0xb5ea4d2 in _prime /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor-find.c:61:11
          #5 0xb5e04c7 in _call_transition /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor.c:1121:12
          #6 0xb5dfba4 in mongoc_cursor_next /src/mongo-c-driver/src/libmongoc/src/mongoc/mongoc-cursor.c:1189:23
          #7 0xb2bd258 in mongocxx::v_noabi::cursor::iterator::operator++() /src/mongo-cxx-driver/src/mongocxx/cursor.cpp:51:9
          #8 0xb2befd4 in mongocxx::v_noabi::cursor::iterator::iterator(mongocxx::v_noabi::cursor*) /src/mongo-cxx-driver/src/mongocxx/cursor.cpp:79:5
          #9 0xb2be6a6 in mongocxx::v_noabi::cursor::begin() /src/mongo-cxx-driver/src/mongocxx/cursor.cpp:66:12
      ... more application specific backtrace
      

      hundreds more will come after that.

       

      It seems that the memory from bson_malloc0 is not properly aligned for the use case it is being used in this case.

        1. out.txt
          26 kB
          Adrian Imboden

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            adrianimboden Adrian Imboden
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: