Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #109

Open
ThomasdenH opened this issue Oct 5, 2019 · 2 comments
Open

Memory leak #109

ThomasdenH opened this issue Oct 5, 2019 · 2 comments

Comments

@ThomasdenH
Copy link

Compiling with CFLAGS="-fsanitize=address" will reliably crash jpeg-hash with
the following image file:

index

@zvezdochiot
Copy link

zvezdochiot commented Oct 5, 2019

jpeg-archive/src/hash.c

Lines 23 to 27 in 8da4bf7

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int pos = y * width + x;
(*hash)[pos] = image[pos] < image[pos + 1];

pos < height * width
pos + 1 !< height * width

Maybe:

    int hw, pos;
    hw = height * width;
    for (pos = 0; pos < (hw - 1); pos++)
    {
        (*hash)[pos] = (image[pos] < image[pos + 1]);
    }
    (*hash)[hw - 1] = (image[hw - 1] < image[0]);

Not?

@zvezdochiot
Copy link

zvezdochiot commented Oct 5, 2019

I will add one more such "miss", but already "from the side":

for (i = 0; i < height; i++) {
for (j = 7; j < width - 1; j += 8) {
double calc;
cnt++;
calc = abs(DVAL(j) - DVAL(j + 1));
calc /= (abs(DVAL(j - 1) - DVAL(j)) + abs(DVAL(j + 1) - DVAL(j + 2)) + 0.0001) / 2.0;

to:

 for (j = 7; j < width - 2; j += 8) {

for (i = 7; i < height - 1; i += 8) {
for (j = 0; j < width; j++) {
double calc;
cnt++;
calc = abs(DVAL(j) - HDVAL(j, 1));
calc /= (abs(HDVAL(j, -1) - DVAL(j)) + abs(HDVAL(j, 1) - HDVAL(j, 2)) + 0.0001) / 2.0;

to:

 for (i = 7; i < height - 2; i += 8) {

See https://github.com/ImageProcessing-ElectronicPublications/libsmallfry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants