Skip to content

Commit

Permalink
Fix jpg contains garbage bytes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhuai committed Dec 21, 2023
1 parent 4fe7ec0 commit 8f94e1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions imageinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ static const std::vector<IIDetector> s_ii_detectors = { // NOLINT(cert-err58-cpp
while (offset + 9 <= length) {
buffer = ri.readBuffer(offset, 9);
uint16_t sectionSize = buffer.readU16BE(2);
if (!buffer.cmp(0, 1, "\xFF")) {
// skip garbage bytes
offset += 1;
continue;
}

// 0xFFC0 is baseline standard (SOF0)
// 0xFFC1 is baseline optimized (SOF1)
Expand Down
Binary file added images/valid/jpg/sample2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int main() {
ASSET_II(IMAGES_DIRECTORY "valid/jpg/optimized.jpg", II_ERR_OK, II_FORMAT_JPEG, 123l, 456l);
ASSET_II(IMAGES_DIRECTORY "valid/jpg/progressive.jpg", II_ERR_OK, II_FORMAT_JPEG, 123l, 456l);
ASSET_II(IMAGES_DIRECTORY "valid/jpg/sample.jpg", II_ERR_OK, II_FORMAT_JPEG, 123l, 456l);
ASSET_II(IMAGES_DIRECTORY "valid/jpg/sample2.jpg", II_ERR_OK, II_FORMAT_JPEG, 1200l, 1603l);
ASSET_II(IMAGES_DIRECTORY "valid/jpg/sampleExported.jpg", II_ERR_OK, II_FORMAT_JPEG, 123l, 456l);
ASSET_II(IMAGES_DIRECTORY "valid/jpg/very-large.jpg", II_ERR_OK, II_FORMAT_JPEG, 4800l, 3600l);
}
Expand Down

0 comments on commit 8f94e1f

Please sign in to comment.