Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

cannot read a persisted json object file with manual checksum #3173

Open
wincss opened this issue Jul 20, 2018 · 0 comments
Open

cannot read a persisted json object file with manual checksum #3173

wincss opened this issue Jul 20, 2018 · 0 comments

Comments

@wincss
Copy link
Contributor

wincss commented Jul 20, 2018

I modified some content in miner.json and changed checksum to manual

"Miner Settings"
"0.5.0"
"manual"
{
... content here ...
}

siad treat it as a wrong checksum and ignore the file content.

https://github.com/NebulousLabs/Sia/blob/master/persist/json.go#L70

	// Determine whether the leading bytes contain a checksum. A proper checksum
	// will be 67 bytes (quote, 64 byte checksum, quote, newline). A manual
	// checksum will be the characters "manual\n" (9 characters). If neither
	// decode correctly, it is assumed that there is no checksum at all.
	var checksum crypto.Hash
	err = json.Unmarshal(remainingBytes[:67], &checksum)
	if err == nil && checksum == crypto.HashBytes(remainingBytes[68:]) {
		// Checksum is proper, and matches the data. Update the data portion to
		// exclude the checksum.
		remainingBytes = remainingBytes[68:]
	} else {
		// Cryptographic checksum failed, try interpreting a manual checksum.
		var manualChecksum string
		err := json.Unmarshal(remainingBytes[:8], &manualChecksum)    // Line 70
		if err == nil && manualChecksum == "manual" {
			// Manual checksum is proper. Update the remaining data to exclude
			// the manual checksum.
			remainingBytes = remainingBytes[9:]    // Line 74
		}
	}

In line 70, it try to json.Unmarshal with remainingBytes[:8] which is only 7 bytes.
json.Unmarshal([]byte("\"manual"), &manualChecksum) is always return an error (unexpected end of JSON input), it should be changed to remainingBytes[:9], and also, the remainingBytes[9:] in line 74 should be changed to remainingBytes[10:].

Stack Trace or error message
No

Expected Behavior
treat "manual" as a correct checksum

How to reproduce it (as minimally and precisely as possible)

  1. run siad with miner module (siad -M gctwm)
  2. modify third line of /miner/miner.json to "manual"
  3. restart siad with miner module
  4. it takes very long time to load miner module because latestChangeID from this file is ignored by siad.

Environment

  • Sia version: v1.3.3
  • OS: Debian 8.9 (it doesn't matter)
wincss added a commit to wincss/Sia that referenced this issue Jul 20, 2018
huetsch pushed a commit to HyperspaceApp/Sia that referenced this issue Oct 23, 2018
Combine UPnP code of host and gateway within gateway

Closes NebulousLabs#3173 and NebulousLabs#1864

See merge request NebulousLabs/Sia!3186
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant