- Everything Linux
- Cloud
- DevOps
- Backend Development
- Golang
Editing the gym locations on nutrigoals.json
leads to corruption on the main app. For example, given
"nusGymsLocations" : [ {
"name" : "🥐",
"latitude" : 1.3007599674153045,
"longitude" : 103.77578206094384
}, {
"name" : "🥐",
"latitude" : 1.304511666901411,
"longitude" : 103.77205745840185
}, {
"name" : "🥐",
"latitude" : 1.2998680145010344,
"longitude" : 103.77528575803385
}, {
"name" : "🥐",
"latitude" : 1.2937696692719094,
"longitude" : 103.77043696074193
}, {
"name" : "🥐",
"latitude" : 1.2930639982706684,
"longitude" : 103.77084097639103
}, {
"name" : "🥐",
"latitude" : 1.2918512226940035,
"longitude" : 103.77477995285786
} ],
The app yields
Same issue can be found when editing the latitude/longitude of the gyms.
Considered low severity.
In nutrigoals.json
, I notice that you can edit calorie, height, weight, idealWeight, gender and age to "invalid" values (invalid, in the terms of the allowable set of values in the UG).
For example, editing values to this:
{
"foods" : [ ],
"nusGymsLocations" : [ {
"name" : "MPSH",
"latitude" : 1.3007599674153045,
"longitude" : 103.77578206094384
}, {
"name" : "STEPHEN RIADY CENTRE",
"latitude" : 1.304511666901411,
"longitude" : 103.77205745840185
}, {
"name" : "USC",
"latitude" : 1.2998680145010344,
"longitude" : 103.77528575803385
}, {
"name" : "EUSOFF HALL",
"latitude" : 1.2937696692719094,
"longitude" : 103.77043696074193
}, {
"name" : "TEMASEK HALL",
"latitude" : 1.2930639982706684,
"longitude" : 103.77084097639103
}, {
"name" : "KENT RIDGE HALL",
"latitude" : 1.2918512226940035,
"longitude" : 103.77477995285786
} ],
"calorieTarget" : {
"value" : "-10"
},
"user" : {
"height" : {
"value" : "250"
},
"weight" : {
"value" : "201"
},
"idealWeight" : {
"value" : "300"
},
"gender" : {
"value" : "K"
},
"age" : {
"value" : "108"
},
"bmi" : {
"value" : "-1",
"height" : {
"value" : "250"
},
"weight" : {
"value" : "201"
}
}
}
}
Yields this when profile
is run:
When food items are added: add n/bread c/100 t/breakfast
, then the program yields this:
This also results in an application crash with no way to recover when the values cannot be parsed. For instance, a nutrigoals.json
of this:
{
"foods" : [ {
"calorie" : "150",
"tagged" : "breakfast",
"dateTime" : "2022-09-15T08:00",
"name" : "cereal"
}, {
"calorie" : "300",
"tagged" : "breakfast",
"dateTime" : "2022-10-23T09:00",
"name" : "croissant"
}, {
"calorie" : "70",
"tagged" : "breakfast",
"dateTime" : "2022-11-11T16:41:48.534996800",
"name" : "bread"
}, {
"calorie" : "120",
"tagged" : "breakfast",
"dateTime" : "2022-11-11T16:41:48.534996800",
"name" : "milo"
}, {
"calorie" : "500",
"tagged" : "lunch",
"dateTime" : "2022-09-15T14:00",
"name" : "ban mian"
}, {
"calorie" : "500",
"tagged" : "lunch",
"dateTime" : "2022-10-23T12:00",
"name" : "fried rice"
}, {
"calorie" : "100",
"tagged" : "lunch",
"dateTime" : "2022-10-23T13:00",
"name" : "soya milk"
}, {
"calorie" : "80",
"tagged" : "lunch",
"dateTime" : "2022-11-11T16:41:48.535995800",
"name" : "porridge"
}, {
"calorie" : "600",
"tagged" : "dinner",
"dateTime" : "2022-09-15T18:00",
"name" : "laksa"
}, {
"calorie" : "400",
"tagged" : "dinner",
"dateTime" : "2022-10-23T19:00",
"name" : "sushi"
}, {
"calorie" : "1000",
"tagged" : "dinner",
"dateTime" : "2022-11-11T16:41:48.535995800",
"name" : "korean bbq"
} ],
"nusGymsLocations" : [ {
"name" : "MPSH",
"latitude" : 1.3007599674153045,
"longitude" : 103.77578206094384
}, {
"name" : "STEPHEN RIADY CENTRE",
"latitude" : 1.304511666901411,
"longitude" : 103.77205745840185
}, {
"name" : "USC",
"latitude" : 1.2998680145010344,
"longitude" : 103.77528575803385
}, {
"name" : "EUSOFF HALL",
"latitude" : 1.2937696692719094,
"longitude" : 103.77043696074193
}, {
"name" : "TEMASEK HALL",
"latitude" : 1.2930639982706684,
"longitude" : 103.77084097639103
}, {
"name" : "KENT RIDGE HALL",
"latitude" : 1.2918512226940035,
"longitude" : 103.77477995285786
} ],
"calorieTarget" : {
"value" : "2000.5"
},
"user" : {
"height" : {
"value" : "180"
},
"weight" : {
"value" : "60"
},
"idealWeight" : {
"value" : "70"
},
"gender" : {
"value" : "M"
},
"age" : {
"value" : "24"
},
"bmi" : {
"value" : "18.51851851851852",
"height" : {
"value" : "180"
},
"weight" : {
"value" : "60"
}
}
}
}
Results in the application being unable to open with the following error message in console:
, 2022 4:42:57 PM seedu.nutrigoals.MainApp initConfig
INFO: Using config file : config.json
Nov 11, 2022 4:42:57 PM seedu.nutrigoals.MainApp initPrefs
INFO: Using prefs file : preferences.json
Nov 11, 2022 4:42:57 PM seedu.nutrigoals.commons.core.LogsCenter init
INFO: currentLogLevel: INFO
Exception in Application init method
Exception in thread "main" java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:895)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NumberFormatException: For input string: "2000.5"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:784)
at seedu.nutrigoals.model.Calorie.getCalorieValue(Calorie.java:51)
at seedu.nutrigoals.model.Calorie.calculateProportion(Calorie.java:105)
at seedu.nutrigoals.model.ModelManager.calculateCalorieIntakeProgress(ModelManager.java:266)
at seedu.nutrigoals.model.ModelManager.<init>(ModelManager.java:52)
at seedu.nutrigoals.MainApp.initModelManager(MainApp.java:93)
at seedu.nutrigoals.MainApp.init(MainApp.java:64)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:824)
... 2 more
A similar message is displayed with any invalid values that cannot be parsed as integers.
Considered medium severity because this requires a deliberate edit of the save file, but the application is unable to recover from this.
test test
When the json object identified by "nusGymsLocations"
is deleted, the app is unable to open with a NullPointerException
.
I.e. with the JSON file:
{
"foods" : [ ],
"calorieTarget" : {
"value" : "2000"
},
"user" : {
"height" : {
"value" : "0"
},
"weight" : {
"value" : "0"
},
"idealWeight" : {
"value" : "0"
},
"gender" : {
"value" : "M"
},
"age" : {
"value" : "0"
},
"bmi" : {
"value" : "NaN",
"height" : {
"value" : "0"
},
"weight" : {
"value" : "0"
}
}
}
}
The app fails to open with the error log:
PS C:\Users\Dernbu\Downloads\CS2103 PE\files-for-pe\New folder> java -jar .\[CS2103T-T17-2][NutriGoals].jar
Nov 11, 2022 4:51:48 PM seedu.nutrigoals.MainApp init
INFO: =============================[ Initializing NutriGoals ]===========================
Nov 11, 2022 4:51:48 PM seedu.nutrigoals.MainApp initConfig
INFO: Using config file : config.json
Nov 11, 2022 4:51:48 PM seedu.nutrigoals.MainApp initPrefs
INFO: Using prefs file : preferences.json
Nov 11, 2022 4:51:48 PM seedu.nutrigoals.commons.core.LogsCenter init
INFO: currentLogLevel: INFO
Exception in Application init method
Exception in thread "main" java.lang.RuntimeException: Exception in Application init method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:895)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:208)
at seedu.nutrigoals.model.NutriGoals.setNusGymsLocations(NutriGoals.java:144)
at seedu.nutrigoals.storage.JsonSerializableNutriGoals.toModelType(JsonSerializableNutriGoals.java:67)
at seedu.nutrigoals.storage.JsonNutriGoalsStorage.readNutriGoals(JsonNutriGoalsStorage.java:55)
at seedu.nutrigoals.storage.StorageManager.readNutriGoals(StorageManager.java:64)
at seedu.nutrigoals.storage.StorageManager.readNutriGoals(StorageManager.java:58)
at seedu.nutrigoals.MainApp.initModelManager(MainApp.java:80)
at seedu.nutrigoals.MainApp.init(MainApp.java:64)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:824)
... 2 more
In fact, any random characters in the nusGymsLocations
key will cause the application to crash
{
"foods" : [ ],
"nusGysdlkfjmsLocations" : [ {
"name" : "MPSH",
...
causes a similar exception.
Considered a High severity bug because any user could accidentally type characters into the relevant line, but the app becomes unrecoverable afterwards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.