avoid out-of-bounds panic in rbf

We've seen this happen with relatively large datasets with a relatively low
max-file-size. The solution we came up with was to increase the max-file-size
config option, which works, but we still don't want there to be a panic if we
hit this again.

see https://molecula.atlassian.net/browse/FB-1381 for more information.
This commit is contained in:
reesporte 2022-06-10 11:00:02 -05:00 committed by reesporte
parent 5b11f3b3b1
commit a97c877f86

View file

@ -815,7 +815,15 @@ func (db *DB) writeDBPage(pgno uint32, page []byte) error {
func (db *DB) readDBPage(pgno uint32) ([]byte, error) {
offset := int64(pgno) * PageSize
return db.data[offset : offset+PageSize], nil
// FB-1381
// Verify page number requested is within the current size of database.
bound := offset + PageSize
if sz := int64(len(db.data)); bound >= sz {
return nil, fmt.Errorf("rbf: page read out of bounds, pgno=%d upper-bound=%d file-size=%d", pgno, bound, sz)
}
return db.data[offset:bound], nil
}
// readWALPageByID reads a WAL page by WAL ID.