Skip to content

[BUG] method zslInsert in t_zset.c update and rank array length need not maxlevel and unsigned int may overflow #8043

@galleChristian

Description

@galleChristian

Describe the bug
`
zskiplistNode *zslInsert(zskiplist *zsl, double score, sds ele) {

zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;

unsigned int rank[ZSKIPLIST_MAXLEVEL];
`
A short description of the bug.

To reproduce

Steps to reproduce the behavior and/or a minimal code sample.

Expected behavior
`
zskiplistNode *zslInsert(zskiplist *zsl, double score, sds ele) {

//---------------------------impovement-------------------------------------------

int level = zslRandomLevel(); // 1st obtains new level value

int max = max(level, zsl->level);

zskiplistNode *update[max]; // low probability to reach ZSKIPLIST_MAXLEVEL

//------------------------------------bug fix--------------------------------------------------------------
// from server.h
// unsigned long length; unsigned long span;
// #define ZSKIPLIST_MAXLEVEL 32 /* Should be enough for 2^64 elements /
// #define ZSKIPLIST_P 0.25 /
Skiplist P = 1/4 */

// if x will be inserted at the end of list, and length has been greater than max of unsigned int, overflow can occur.

unsigned long rank[max];// long not int

`
A description of what you expected to happen.

Additional information

Any additional information that is relevant to the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions