MCPcopy Create free account
hub / github.com/F-Stack/f-stack / streamValidateListpackIntegrity

Function streamValidateListpackIntegrity

app/redis-6.2.6/src/t_stream.c:3581–3668  ·  view source on GitHub ↗

Validate the integrity stream listpack entries structure. Both in term of a * valid listpack, but also that the structure of the entires matches a valid * stream. return 1 if valid 0 if not valid. */

Source from the content-addressed store, hash-verified

3579 * valid listpack, but also that the structure of the entires matches a valid
3580 * stream. return 1 if valid 0 if not valid. */
3581int streamValidateListpackIntegrity(unsigned char *lp, size_t size, int deep) {
3582 int valid_record;
3583 unsigned char *p, *next;
3584
3585 /* Since we don't want to run validation of all records twice, we'll
3586 * run the listpack validation of just the header and do the rest here. */
3587 if (!lpValidateIntegrity(lp, size, 0))
3588 return 0;
3589
3590 /* In non-deep mode we just validated the listpack header (encoded size) */
3591 if (!deep) return 1;
3592
3593 next = p = lpValidateFirst(lp);
3594 if (!lpValidateNext(lp, &next, size)) return 0;
3595 if (!p) return 0;
3596
3597 /* entry count */
3598 int64_t entry_count = lpGetIntegerIfValid(p, &valid_record);
3599 if (!valid_record) return 0;
3600 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3601
3602 /* deleted */
3603 int64_t deleted_count = lpGetIntegerIfValid(p, &valid_record);
3604 if (!valid_record) return 0;
3605 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3606
3607 /* num-of-fields */
3608 int64_t master_fields = lpGetIntegerIfValid(p, &valid_record);
3609 if (!valid_record) return 0;
3610 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3611
3612 /* the field names */
3613 for (int64_t j = 0; j < master_fields; j++) {
3614 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3615 }
3616
3617 /* the zero master entry terminator. */
3618 int64_t zero = lpGetIntegerIfValid(p, &valid_record);
3619 if (!valid_record || zero != 0) return 0;
3620 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3621
3622 entry_count += deleted_count;
3623 while (entry_count--) {
3624 if (!p) return 0;
3625 int64_t fields = master_fields, extra_fields = 3;
3626 int64_t flags = lpGetIntegerIfValid(p, &valid_record);
3627 if (!valid_record) return 0;
3628 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3629
3630 /* entry id */
3631 lpGetIntegerIfValid(p, &valid_record);
3632 if (!valid_record) return 0;
3633 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3634 lpGetIntegerIfValid(p, &valid_record);
3635 if (!valid_record) return 0;
3636 p = next; if (!lpValidateNext(lp, &next, size)) return 0;
3637
3638 if (!(flags & STREAM_ITEM_FLAG_SAMEFIELDS)) {

Callers 1

rdbLoadObjectFunction · 0.85

Calls 4

lpValidateIntegrityFunction · 0.85
lpValidateFirstFunction · 0.85
lpValidateNextFunction · 0.85
lpGetIntegerIfValidFunction · 0.85

Tested by

no test coverage detected