Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-9411

Fix the handling of uint64_t flags in flags.py and wiredtiger flags

    XMLWordPrintable

Details

    • Build Failure
    • Status: Closed
    • Critical - P2
    • Resolution: Fixed
    • None
    • WT11.0.0, 6.1.0-rc0
    • None
    • 3
    • Storage - Ra 2022-06-13

    Description

      Currently uint64_t flags are not handled properly in flags.py and has caused underflow problems in WiredTiger. The cursor flags is a good example of this:

      /* AUTOMATIC FLAG VALUE GENERATION START 0 */
      #define	WT_CURSTD_APPEND		0x000000001u
      #define	WT_CURSTD_BULK			0x000000002u
      #define	WT_CURSTD_CACHEABLE		0x000000004u
      #define	WT_CURSTD_CACHED		0x000000008u
      #define	WT_CURSTD_DEAD			0x000000010u
      #define	WT_CURSTD_DEBUG_COPY_KEY	0x000000020u
      #define	WT_CURSTD_DEBUG_COPY_VALUE	0x000000040u
      #define	WT_CURSTD_DEBUG_RESET_EVICT	0x000000080u
      #define	WT_CURSTD_DUMP_HEX		0x000000100u
      #define	WT_CURSTD_DUMP_JSON		0x000000200u
      #define	WT_CURSTD_DUMP_PRETTY		0x000000400u
      #define	WT_CURSTD_DUMP_PRINT		0x000000800u
      #define	WT_CURSTD_DUP_NO_VALUE          0x000001000u
      #define	WT_CURSTD_EVICT_REPOSITION     0x000002000u
      #define	WT_CURSTD_HS_READ_ALL		0x000004000u
      #define	WT_CURSTD_HS_READ_COMMITTED	0x000008000u
      #define	WT_CURSTD_IGNORE_TOMBSTONE	0x000010000u
      #define	WT_CURSTD_JOINED		0x000020000u
      #define	WT_CURSTD_KEY_EXT		0x000040000u /* Key points out of tree. */
      #define	WT_CURSTD_KEY_INT		0x000080000u /* Key points into tree. */
      #define	WT_CURSTD_KEY_ONLY		0x000100000u
      #define	WT_CURSTD_META_INUSE		0x000200000u
      #define	WT_CURSTD_OPEN			0x000400000u
      #define	WT_CURSTD_OVERWRITE		0x000800000u
      #define	WT_CURSTD_PREFIX_SEARCH		0x001000000u
      #define	WT_CURSTD_RAW			0x002000000u
      #define	WT_CURSTD_RAW_SEARCH		0x004000000u
      #define	WT_CURSTD_VALUE_EXT		0x008000000u /* Value points out of tree. */
      #define	WT_CURSTD_VALUE_INT		0x010000000u /* Value points into tree. */
      #define WT_CURSTD_BOUND_LOWER    0x020000000u       /* Lower bound. */
      #define WT_CURSTD_BOUND_LOWER_INCLUSIVE 0x040000000u /* Inclusive lower bound. */
      #define WT_CURSTD_BOUND_UPPER           0x080000000u /* Upper bound. */
      #define WT_CURSTD_BOUND_UPPER_INCLUSIVE 0x100000000u /* Inclusive upper bound. */
      #define WT_CURSTD_VERSION_CURSOR	0x200000000u /* Version cursor. */
      /* AUTOMATIC FLAG VALUE GENERATION STOP 64 */
      #define	WT_CURSTD_KEY_SET	(WT_CURSTD_KEY_EXT | WT_CURSTD_KEY_INT)
      #define	WT_CURSTD_VALUE_SET	(WT_CURSTD_VALUE_EXT | WT_CURSTD_VALUE_INT)
      #define WT_CURSTD_BOUNDS_SET (WT_CURSTD_BOUND_LOWER | WT_CURSTD_BOUND_UPPER)
      	uint64_t flags;
      

      Since all the values are in form of unsigned u, this can cause problems when using F_SET, F_ISSET, F_CLR. An example of this problem can be shown through this reproducer where we perform bit manipulation, and we can clear more than what we have intended.

      #include <stdlib.h>
      #include <stdio.h>
      #include <inttypes.h>
      int
      main()
      {
          uint64_t xxx;
          xxx = 0x100000000u;
          printf("xxx %#" PRIx64 "\n", xxx);
          
          xxx = xxx & ~(0x010000000u);
          printf("xxx %#" PRIx64 "\n", xxx); // We get 0 when we are meant to get 0x100000000
       
          return (0);
      }
      

      Attachments

        Activity

          People

            jie.chen@mongodb.com Jie Chen
            jie.chen@mongodb.com Jie Chen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: