From a97c877f8684a9d20295a4e2871af1e846db9cc9 Mon Sep 17 00:00:00 2001 From: reesporte Date: Fri, 10 Jun 2022 11:00:02 -0500 Subject: [PATCH] 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. --- rbf/db.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rbf/db.go b/rbf/db.go index d13a0a84c..439d443c0 100644 --- a/rbf/db.go +++ b/rbf/db.go @@ -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.