jackc / pgtype

MIT License
314 stars 112 forks source link

Panic when try to read hstore binary #116

Closed laskoviymishka closed 3 years ago

laskoviymishka commented 3 years ago

Example table:

create table test
(
    id bigserial not null primary key,
    changes hstore
);
INSERT INTO test (id, changes) VALUES (1, 'appointment_time => null, created => "2016-07-21 15:15:23.187727+03", postponed_till => null, latitude => 36.2389755249023, created_local => "2016-07-21 15:15:23+03", ticket_id => null, time_slots => "[{\"start_time\": \"2016-07-24T00:00:00\", \"end_time\": \"2016-07-24T23:59:00\"}, {\"start_time\": \"2016-07-25T00:00:00\", \"end_time\": \"2016-07-25T23:59:00\"}, {\"start_time\": \"2016-07-26T00:00:00\", \"end_time\": \"2016-07-26T23:59:00\"}, {\"start_time\": \"2016-07-27T00:00:00\", \"end_time\": \"2016-07-27T23:59:00\"}, {\"start_time\": \"2016-07-28T00:00:00\", \"end_time\": \"2016-07-28T23:59:00\"}, {\"start_time\": \"2016-07-22T00:00:00\", \"end_time\": \"2016-07-22T23:59:00\"}, {\"start_time\": \"2016-07-23T00:00:00\", \"end_time\": \"2016-07-23T23:59:00\"}]", patient_id => 1, specialization_code => therapist, status_updated => "2016-07-21 15:15:23.285021+03", id => 1, doctor_name => null, cancelation_reason_id => null, clinic_id => 2, status => pending, longitude => 99.008171081543');

Seems like somesort of incorrect uint32 parsing:

        keyLen := int(int32(binary.BigEndian.Uint32(src[rp:])))
panic: runtime error: slice bounds out of range [:-16777034]

goroutine 573 [running]:
github.com/jackc/pgx/pgtype.(*Hstore).DecodeBinary(0xc0011d6220, 0xc001a60120, 0xc007510038, 0x3be, 0x1fc8, 0x1, 0x0)
    /-S/vendor/github.com/jackc/pgx/pgtype/hstore.go:125 +0x6a5
github.com/jackc/pgx.(*Rows).Scan(0xc000771ce0, 0xc001f22480, 0x8, 0x8, 0xc00ec9c258, 0x1)
    /-S/vendor/github.com/jackc/pgx/query.go:232 +0xd8c
    /-S/vendor/github.com/cenkalti/backoff/v4/retry.go:55 +0x102
github.com/cenkalti/backoff/v4.RetryNotify(...)
    /-S/vendor/github.com/cenkalti/backoff/v4/retry.go:34
github.com/cenkalti/backoff/v4.Retry(...)
    /-S/vendor/github.com/cenkalti/backoff/v4/retry.go:28
jackc commented 3 years ago

Fixed in 6bda096.