It's hard to tell without an image to try it on, but I would think ImageMagick would rewrite your images properly without the superfluous data. If you are on Linux it is probably installed, look for a program called convert
and/or mogrify
whcih belong to ImageMagick, else you can install it from here.
Then you want a command that does nothing too drastic to your image, so something like this should be pretty harmless:
mogrify -set comment 'Extraneous bytes removed' *.jpg
Back up your files first though, and test before applying to thousands of images!