uavos / apx-gcs

APX Ground Control
GNU Lesser General Public License v3.0
13 stars 12 forks source link

Importing an edited mission (with wrong hash) crashes APX-GCS #71

Closed calumblair closed 8 months ago

calumblair commented 8 months ago

Describe the bug When a yaml mission is imported and the hash does not match or the mission file has been edited, APX-GCS will crash when uploading it to the vehicle. To Reproduce Steps to reproduce the behavior:

  1. Open APX-GCS 11.1.15. Connect to apx simulator and Xplane.
  2. Open the mission planner and open the database
  3. Load the "Sim - seattle- R18" mission into the mission planner (don't upload to vehicle yet)
  4. Export the mission to a file named "default_seattle_sim.mission"
  5. Open the file in a text editor and make any edit, eg modify the title from
    "title": "seattle",

    to

    "title": "seattle_bad_hash",

    See file copied below.

  6. Save the file. The file will now have an incorrect hash.
  7. In mission planner, import the mission from file again. Title will change to "seattle_bad_hash".
  8. Click "upload to vehicle". APX-GCS will hang and become unresponsive. Screenshot:

    Screenshot from 2024-03-13 15-39-24

Expected behavior APX-GCS should tell me that the file has a bad hash, or it should load the file and generate a new hash. It should not hang.

Screenshots Screenshot from 2024-03-13 15-39-24

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

See file below: default_seattle_sim_edited.mission:

{
    "bottomRightLat": 47.43515069589624,
    "bottomRightLon": -122.27104298857725,
    "callsign": "UVH170",
    "distance": 18826,
    "exported": "13 Mar 2024 15:20:57 +0000",
    "format": "11",
    "hash": "2CEDB9681B58E3BB04834C757B5EF4C2998E80EE",
    "lat": 47.46274185180664,
    "lon": -122.30777740478516,
    "pi": [
        {
            "hmsl": "ground",
            "lat": 47.452199374875896,
            "lon": -122.32997174419155,
            "loops": "default",
            "radius": 1200,
            "timeout": "60"
        }
    ],
    "runway": "R18",
    "rw": [
        {
            "approach": 1800,
            "dE": -17,
            "dN": -3068,
            "hmsl": "default",
            "lat": 47.46274185180664,
            "lon": -122.30777740478516,
            "type": "right"
        }
    ],
    "time": 1710343257120,
    "title": "seattle_bad_hash",
    "topLeftLat": 47.487110336614926,
    "topLeftLon": -122.345931173777,
    "tw": [
        {
            "lat": 47.46312713623047,
            "lon": -122.30776977539062
        },
        {
            "lat": 47.4600944519043,
            "lon": -122.30780029296875
        },
        {
            "lat": 47.4600830078125,
            "lon": -122.30618286132812
        },
        {
            "lat": 47.46348571777344,
            "lon": -122.30616760253906
        },
        {
            "lat": 47.46349334716797,
            "lon": -122.30731201171875
        },
        {
            "lat": 47.46330642700195,
            "lon": -122.3077621459961
        },
        {
            "lat": 47.462913513183594,
            "lon": -122.30776977539062
        }
    ],
    "version": "11.1.15",
    "wp": [
        {
            "actions": {
                "poi": "1"
            },
            "altitude": 2000,
            "lat": 47.44905090332031,
            "lon": -122.2920150756836,
            "type": "direct"
        },
        {
            "altitude": 2000,
            "lat": 47.47319793701172,
            "lon": -122.2713623046875,
            "type": "direct"
        },
        {
            "altitude": 2000,
            "lat": 47.44598388671875,
            "lon": -122.30022430419922,
            "type": "track"
        },
        {
            "altitude": 2000,
            "lat": 47.473297119140625,
            "lon": -122.28264617919922,
            "type": "direct"
        },
        {
            "altitude": 2000,
            "lat": 47.4654426574707,
            "lon": -122.29686737060547,
            "type": "direct"
        },
        {
            "altitude": 2000,
            "lat": 47.46375274658203,
            "lon": -122.34414672851562,
            "type": "direct"
        }
    ]
}
calumblair commented 8 months ago

Ideally, when importing a file with no hash (as distinct to an incorrect hash), APX-GCS should generate a valid hash.

uavinda commented 8 months ago

The problem is here (buffer overflow): https://github.com/uavos/apx-gcs/blob/ba6fd47077d8f8d095329122913a1d7e8610808e/src/Plugins/Protocols/PApx/PApxMission.cpp#L445

uavinda commented 8 months ago

Mission hash is not used by the mission import function. https://github.com/uavos/apx-gcs/blob/9977a6a6c2cd1fef557493fc66d30e4f2677ea0f/src/lib/ApxGcs/Mission/VehicleMission.cpp#L337

The purpose of HASH field is to speed-up files identification and check integrity of files when needed by other utilities. Also, the hash value does not depend on mission title.