airmash-refugees / airmash-frontend

"Semi-pristine" copy of last official Airmash app
https://airmash.online
43 stars 24 forks source link

Preventing "Offset is outside the bounds of the DataView" error #25

Closed wight-airmash closed 4 years ago

wight-airmash commented 4 years ago

During the protocol update process, there may be cases when the frontend with the extended schemas has already been deployed but some of the servers have not yet been updated. Because of this, the frontend parser may go beyond the boundaries of the smaller than expected binary packet.

To avoid waiting for all servers to update, it may be usefull to add a condition if the parser has reached the packet boundary:

for (var fieldIdx = 0; fieldIdx < schema.length; fieldIdx++) { 
  if (inputPos === dataView.byteLength) {
    break;
  }

https://github.com/airmash-refugees/airmash-frontend/blob/b19a3d611d3e1a37f7747168edb4f7a5076ecc68/src/js/Network.js#L551-L562

congratulatio commented 4 years ago

Agreed, I'd wrapped the decoder in a try-catch to mitigate this, but this condition should be dealt with directly too - I've applied your fix in https://github.com/airmash-refugees/airmash-frontend/commit/f5b7bd909957967130f6a617cdc1b66ad28a8447.