Skip to content

Commit

Permalink
Avoid overflowing 32-bit systems when mmapping value log of default s…
Browse files Browse the repository at this point in the history
…ize. Correct an overflow check.
  • Loading branch information
manishrjain committed Aug 10, 2018
1 parent be3a85f commit 341a135
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ var DefaultOptions = Options{
NumVersionsToKeep: 1,
// Nothing to read/write value log using standard File I/O
// MemoryMap to mmap() the value log files
ValueLogFileSize: 1 << 30,
// (2^30 - 1)*2 when mmapping < 2^31 - 1, max int32.
// -1 so 2*ValueLogFileSize won't overflow on 32-bit systems.
ValueLogFileSize: 1<<30 - 1,

ValueLogMaxEntries: 1000000,
ValueThreshold: 32,
Truncate: false,
Expand Down
2 changes: 1 addition & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ func (vlog *valueLog) write(reqs []*request) error {
}

newid := atomic.AddUint32(&vlog.maxFid, 1)
y.AssertTruef(newid <= math.MaxUint32, "newid will overflow uint32: %v", newid)
y.AssertTruef(newid > 0, "newid has overflown uint32: %v", newid)
newlf, err := vlog.createVlogFile(newid)
if err != nil {
return err
Expand Down

0 comments on commit 341a135

Please sign in to comment.