mirror of
https://github.com/olikraus/u8g2.git
synced 2026-09-11 09:12:33 +00:00
Honor binary PBM input in the font converter
The converter recognizes P4 files but never reads their raster data, so valid binary PBM input is silently converted from uninitialized bitmap storage. Read P4 bytes in their specified MSB-first order, open inputs in binary mode, and propagate truncated-input failures to the command-line result. Constraint: Preserve existing P1 output and the converter's internal LSB-first bitmap layout\nRejected: Copy P4 rows directly into bitmap storage | PBM raster bits are MSB-first while the existing internal representation is LSB-first\nConfidence: high\nScope-risk: narrow\nReversibility: clean\nDirective: Keep binary PBM row padding and bit order explicit when changing this parser\nTested: MinGW GCC 8 and WSL GCC with -Wall -Wextra -Werror; real-source P1/P4 equivalence fixture; truncated P4 rejection; Linux ASan/UBSan; existing Scroll-o-Sprites P1 output matches baseline across 5416 lines\nNot-tested: Other external PBM producer variants with headers split differently
This commit is contained in:
+33
-4
@@ -163,6 +163,24 @@ int pbm_ReadFP(pbm_t *pbm)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t x, y;
|
||||
int c = 0;
|
||||
for( y = 0; y < pbm->h; y++ )
|
||||
{
|
||||
for( x = 0; x < pbm->w; x++ )
|
||||
{
|
||||
if ( (x & 7) == 0 )
|
||||
{
|
||||
c = fgetc(pbm->fp);
|
||||
if ( c == EOF )
|
||||
return 0;
|
||||
}
|
||||
pbm_SetPixel(pbm, x, y, (c & (0x80 >> (x & 7))) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -271,15 +289,22 @@ void pbm_Show(pbm_t *pbm)
|
||||
|
||||
int pbm_ReadFilename(pbm_t *pbm, const char *name)
|
||||
{
|
||||
pbm->fp = fopen(name, "r");
|
||||
int result;
|
||||
pbm->bitmap = NULL;
|
||||
pbm->fp = fopen(name, "rb");
|
||||
pbm->is_ascii = 0;
|
||||
if ( pbm->fp == NULL )
|
||||
return 0;
|
||||
|
||||
pbm_ReadFP(pbm);
|
||||
result = pbm_ReadFP(pbm);
|
||||
fclose(pbm->fp);
|
||||
if ( result == 0 )
|
||||
{
|
||||
free(pbm->bitmap);
|
||||
pbm->bitmap = NULL;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +382,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
pbm_ReadFilename(&pbm, argv[1]);
|
||||
if ( pbm_ReadFilename(&pbm, argv[1]) == 0 )
|
||||
{
|
||||
fprintf(stderr, "Failed to read %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
out(&pbm, stdout, argv[1]);
|
||||
//printf("Size: %d x %d\n", pbm.w, pbm.h);
|
||||
//pbm_Show(&pbm);
|
||||
|
||||
Reference in New Issue
Block a user