Fixed a potential bug that could cause a segment fault when insert a large tuple. #716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Statement
In the file
src/storage/page/table_page.cpp
, Here is aTablePage::GetNextTupleOffset
function.Since
tuple_offset
is unsigned long, tuple_offset will be greater than the value of offset_size after underflow occurs. Therefore, the condition ofif
clause is not satisfied, we will return an error tuple_offset(the value of tuple_offset exceeds the page size). When we insert a tuple at this position, a segment fault occurs.How to hack it
I reproduced this fault using BusTub Web Shell(Fall 2023).
First, create a table with larger schema.
Then, insert some tuples into it. In this example, I inserted$3$ tuples of $2500$ bytes long.
Then, You should be able to observe that the program has failed.
![pic](https://private-user-images.githubusercontent.com/78433231/342798158-535d3c6a-04ca-40ed-9f0b-c1d4a39707f6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ5NzMwNjEsIm5iZiI6MTcyNDk3Mjc2MSwicGF0aCI6Ii83ODQzMzIzMS8zNDI3OTgxNTgtNTM1ZDNjNmEtMDRjYS00MGVkLTlmMGItYzFkNGEzOTcwN2Y2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI5VDIzMDYwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTMxOGJmZWI5OWM1OTRmZDlkOThiOTAyNDhhOGVmM2MyNWZlMzYyOWFkYTJiMTA1ZmYxYWFjMTg3YjIxZmY1ZDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.VU2n2Rgow4N2NX_kPhK5ZFbAwk4DpN6OVYftnSJ3Ndg)