diff --git a/src/create.c b/src/create.c index a750846..0f3735c 100644 --- a/src/create.c +++ b/src/create.c @@ -994,11 +994,15 @@ CreateXImage( #if !defined(FOR_MSW) && !defined(AMIGA) if (height != 0 && (*image_return)->bytes_per_line >= INT_MAX / height) { XDestroyImage(*image_return); + *image_return = NULL; return XpmNoMemory; } /* now that bytes_per_line must have been set properly alloc data */ - if((*image_return)->bytes_per_line == 0 || height == 0) + if((*image_return)->bytes_per_line == 0 || height == 0) { + XDestroyImage(*image_return); + *image_return = NULL; return XpmNoMemory; + } (*image_return)->data = (char *) XpmMalloc((*image_return)->bytes_per_line * height); diff --git a/src/data.c b/src/data.c index 898889c..6e87455 100644 --- a/src/data.c +++ b/src/data.c @@ -108,7 +108,7 @@ ParseComment(xpmData *data) n++; s2++; } while (c == *s2 && *s2 != '\0' && c); - if (*s2 == '\0') { + if (*s2 == '\0' || c == '\0') { /* this is the end of the comment */ notend = 0; data->cptr--; @@ -174,6 +174,10 @@ ParseComment(xpmData *data) notend = 0; Ungetc(data, *s, file); } + else if (c == EOF) { + /* hit end of file before the end of the comment */ + return XpmFileInvalid; + } } return 0; } @@ -191,19 +195,23 @@ xpmNextString(xpmData *data) register char c; /* get to the end of the current string */ - if (data->Eos) - while ((c = *data->cptr++) && c != data->Eos); + if (data->Eos) { + while ((c = *data->cptr++) && c != data->Eos && c != '\0'); + + if (c == '\0') + return XpmFileInvalid; + } /* * then get to the beginning of the next string looking for possible * comment */ if (data->Bos) { - while ((c = *data->cptr++) && c != data->Bos) + while ((c = *data->cptr++) && c != data->Bos && c != '\0') if (data->Bcmt && c == data->Bcmt[0]) ParseComment(data); } else if (data->Bcmt) { /* XPM2 natural */ - while ((c = *data->cptr++) == data->Bcmt[0]) + while (((c = *data->cptr++) == data->Bcmt[0]) && c != '\0') ParseComment(data); data->cptr--; } @@ -212,9 +220,13 @@ xpmNextString(xpmData *data) FILE *file = data->stream.file; /* get to the end of the current string */ - if (data->Eos) + if (data->Eos) { while ((c = Getc(data, file)) != data->Eos && c != EOF); + if (c == EOF) + return XpmFileInvalid; + } + /* * then get to the beginning of the next string looking for possible * comment @@ -230,7 +242,7 @@ xpmNextString(xpmData *data) Ungetc(data, c, file); } } - return 0; + return XpmSuccess; } @@ -247,13 +259,13 @@ xpmNextWord( int c; if (!data->type || data->type == XPMBUFFER) { - while (isspace(c = *data->cptr) && c != data->Eos) + while ((c = *data->cptr) && isspace(c) && (c != data->Eos)) data->cptr++; do { c = *data->cptr++; *buf++ = c; n++; - } while (!isspace(c) && c != data->Eos && n < buflen); + } while (c && !isspace(c) && (c != data->Eos) && (n < buflen)); n--; data->cptr--; } else { diff --git a/src/parse.c b/src/parse.c index c19209c..e97d771 100644 --- a/src/parse.c +++ b/src/parse.c @@ -391,6 +391,13 @@ ParsePixels( { unsigned int *iptr, *iptr2 = NULL; /* found by Egbert Eich */ unsigned int a, x, y; + int ErrorStatus; + + if ((width == 0) && (height != 0)) + return (XpmFileInvalid); + + if ((height == 0) && (width != 0)) + return (XpmFileInvalid); if ((height > 0 && width >= UINT_MAX / height) || width * height >= UINT_MAX / sizeof(unsigned int)) @@ -428,7 +435,11 @@ ParsePixels( colidx[(unsigned char)colorTable[a].string[0]] = a + 1; for (y = 0; y < height; y++) { - xpmNextString(data); + ErrorStatus = xpmNextString(data); + if (ErrorStatus != XpmSuccess) { + XpmFree(iptr2); + return (ErrorStatus); + } for (x = 0; x < width; x++, iptr++) { int c = xpmGetC(data); @@ -475,7 +486,11 @@ do \ } for (y = 0; y < height; y++) { - xpmNextString(data); + ErrorStatus = xpmNextString(data); + if (ErrorStatus != XpmSuccess) { + XpmFree(iptr2); + return (ErrorStatus); + } for (x = 0; x < width; x++, iptr++) { int cc1 = xpmGetC(data); if (cc1 > 0 && cc1 < 256) { @@ -515,7 +530,11 @@ do \ xpmHashAtom *slot; for (y = 0; y < height; y++) { - xpmNextString(data); + ErrorStatus = xpmNextString(data); + if (ErrorStatus != XpmSuccess) { + XpmFree(iptr2); + return (ErrorStatus); + } for (x = 0; x < width; x++, iptr++) { for (a = 0, s = buf; a < cpp; a++, s++) { int c = xpmGetC(data); @@ -535,7 +554,11 @@ do \ } } else { for (y = 0; y < height; y++) { - xpmNextString(data); + ErrorStatus = xpmNextString(data); + if (ErrorStatus != XpmSuccess) { + XpmFree(iptr2); + return (ErrorStatus); + } for (x = 0; x < width; x++, iptr++) { for (a = 0, s = buf; a < cpp; a++, s++) { int c = xpmGetC(data); diff --git a/windows/vs17/.vs/libxpm/FileContentIndex/91f4d962-497b-4902-b25e-2325e5351009.vsidx b/windows/vs17/.vs/libxpm/FileContentIndex/91f4d962-497b-4902-b25e-2325e5351009.vsidx new file mode 100644 index 0000000..85188f9 Binary files /dev/null and b/windows/vs17/.vs/libxpm/FileContentIndex/91f4d962-497b-4902-b25e-2325e5351009.vsidx differ diff --git a/windows/vs17/.vs/libxpm/v17/.suo b/windows/vs17/.vs/libxpm/v17/.suo new file mode 100644 index 0000000..dde07ea Binary files /dev/null and b/windows/vs17/.vs/libxpm/v17/.suo differ diff --git a/windows/vs17/.vs/libxpm/v17/Browse.VC.db b/windows/vs17/.vs/libxpm/v17/Browse.VC.db new file mode 100644 index 0000000..547072c Binary files /dev/null and b/windows/vs17/.vs/libxpm/v17/Browse.VC.db differ diff --git a/windows/vs17/.vs/libxpm/v17/DocumentLayout.backup.json b/windows/vs17/.vs/libxpm/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..b4fc3eb --- /dev/null +++ b/windows/vs17/.vs/libxpm/v17/DocumentLayout.backup.json @@ -0,0 +1,51 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\git\\winlibs\\libxpm\\windows\\vs17\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{5DC29C20-FE21-47EF-AC7D-641BD7DDD962}|libxpm.vcxproj|D:\\git\\winlibs\\libxpm\\src\\XpmI.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + }, + { + "AbsoluteMoniker": "D:0:0:{5DC29C20-FE21-47EF-AC7D-641BD7DDD962}|libxpm.vcxproj|D:\\git\\winlibs\\libxpm\\src\\Attrib.c||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "XpmI.h", + "DocumentMoniker": "D:\\git\\winlibs\\libxpm\\src\\XpmI.h", + "RelativeDocumentMoniker": "..\\..\\src\\XpmI.h", + "ToolTip": "D:\\git\\winlibs\\libxpm\\src\\XpmI.h", + "RelativeToolTip": "..\\..\\src\\XpmI.h", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", + "WhenOpened": "2024-09-11T11:50:14.451Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "Attrib.c", + "DocumentMoniker": "D:\\git\\winlibs\\libxpm\\src\\Attrib.c", + "RelativeDocumentMoniker": "..\\..\\src\\Attrib.c", + "ToolTip": "D:\\git\\winlibs\\libxpm\\src\\Attrib.c", + "RelativeToolTip": "..\\..\\src\\Attrib.c", + "ViewState": "AgIAABIAAAAAAAAAAAAAACcAAAAOAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000423|", + "WhenOpened": "2024-09-11T11:49:52.976Z" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/windows/vs17/.vs/libxpm/v17/DocumentLayout.json b/windows/vs17/.vs/libxpm/v17/DocumentLayout.json new file mode 100644 index 0000000..29c2cde --- /dev/null +++ b/windows/vs17/.vs/libxpm/v17/DocumentLayout.json @@ -0,0 +1,51 @@ +{ + "Version": 1, + "WorkspaceRootPath": "D:\\git\\winlibs\\libxpm\\windows\\vs17\\", + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{5DC29C20-FE21-47EF-AC7D-641BD7DDD962}|libxpm.vcxproj|D:\\git\\winlibs\\libxpm\\src\\XpmI.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + }, + { + "AbsoluteMoniker": "D:0:0:{5DC29C20-FE21-47EF-AC7D-641BD7DDD962}|libxpm.vcxproj|D:\\git\\winlibs\\libxpm\\src\\Attrib.c||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}" + } + ], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "XpmI.h", + "DocumentMoniker": "D:\\git\\winlibs\\libxpm\\src\\XpmI.h", + "RelativeDocumentMoniker": "..\\..\\src\\XpmI.h", + "ToolTip": "D:\\git\\winlibs\\libxpm\\src\\XpmI.h", + "RelativeToolTip": "..\\..\\src\\XpmI.h", + "ViewState": "AgIAAAAAAAAAAAAAAAAAAAgAAAA7AAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|", + "WhenOpened": "2024-09-11T11:50:14.451Z", + "EditorCaption": "" + }, + { + "$type": "Document", + "DocumentIndex": 1, + "Title": "Attrib.c", + "DocumentMoniker": "D:\\git\\winlibs\\libxpm\\src\\Attrib.c", + "RelativeDocumentMoniker": "..\\..\\src\\Attrib.c", + "ToolTip": "D:\\git\\winlibs\\libxpm\\src\\Attrib.c", + "RelativeToolTip": "..\\..\\src\\Attrib.c", + "ViewState": "AgIAABIAAAAAAAAAAAAAACcAAAAOAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000423|", + "WhenOpened": "2024-09-11T11:49:52.976Z" + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/windows/vs17/.vs/libxpm/v17/Solution.VC.db b/windows/vs17/.vs/libxpm/v17/Solution.VC.db new file mode 100644 index 0000000..dec4d46 Binary files /dev/null and b/windows/vs17/.vs/libxpm/v17/Solution.VC.db differ diff --git a/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/2b7ed7c1a9d60ec9/ATTRIB.ipch b/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/2b7ed7c1a9d60ec9/ATTRIB.ipch new file mode 100644 index 0000000..eed5d8f Binary files /dev/null and b/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/2b7ed7c1a9d60ec9/ATTRIB.ipch differ diff --git a/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/78d9f47719f66a16/ATTRIB.ipch b/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/78d9f47719f66a16/ATTRIB.ipch new file mode 100644 index 0000000..64a25b0 Binary files /dev/null and b/windows/vs17/.vs/libxpm/v17/ipch/AutoPCH/78d9f47719f66a16/ATTRIB.ipch differ diff --git a/windows/vs17/libxpm.sln b/windows/vs17/libxpm.sln new file mode 100644 index 0000000..4239805 --- /dev/null +++ b/windows/vs17/libxpm.sln @@ -0,0 +1,40 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.9 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxpm", "libxpm.vcxproj", "{5DC29C20-FE21-47EF-AC7D-641BD7DDD962}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + DLL Debug|Win32 = DLL Debug|Win32 + DLL Debug|x64 = DLL Debug|x64 + DLL Release|Win32 = DLL Release|Win32 + DLL Release|x64 = DLL Release|x64 + Static Debug|Win32 = Static Debug|Win32 + Static Debug|x64 = Static Debug|x64 + Static Release|Win32 = Static Release|Win32 + Static Release|x64 = Static Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Debug|Win32.ActiveCfg = DLL Debug|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Debug|Win32.Build.0 = DLL Debug|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Debug|x64.ActiveCfg = DLL Debug|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Debug|x64.Build.0 = DLL Debug|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Release|Win32.ActiveCfg = DLL Release|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Release|Win32.Build.0 = DLL Release|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Release|x64.ActiveCfg = DLL Release|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.DLL Release|x64.Build.0 = DLL Release|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Debug|Win32.ActiveCfg = Static Debug|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Debug|Win32.Build.0 = Static Debug|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Debug|x64.ActiveCfg = Static Debug|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Debug|x64.Build.0 = Static Debug|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Release|Win32.ActiveCfg = Static Release|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Release|Win32.Build.0 = Static Release|Win32 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Release|x64.ActiveCfg = Static Release|x64 + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962}.Static Release|x64.Build.0 = Static Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/windows/vs17/libxpm.vcxproj b/windows/vs17/libxpm.vcxproj new file mode 100644 index 0000000..c487382 --- /dev/null +++ b/windows/vs17/libxpm.vcxproj @@ -0,0 +1,344 @@ + + + + + DLL Debug + Win32 + + + DLL Debug + x64 + + + DLL Release + Win32 + + + DLL Release + x64 + + + Static Debug + Win32 + + + Static Debug + x64 + + + Static Release + Win32 + + + Static Release + x64 + + + + {5DC29C20-FE21-47EF-AC7D-641BD7DDD962} + libxpm + Win32Proj + 10.0.22621.0 + + + + StaticLibrary + v143 + + + StaticLibrary + v143 + Unicode + true + + + DynamicLibrary + v143 + Unicode + true + + + DynamicLibrary + v143 + Unicode + + + StaticLibrary + v143 + + + StaticLibrary + v143 + Unicode + true + + + DynamicLibrary + v143 + Unicode + true + + + DynamicLibrary + v143 + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>11.0.50727.1 + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + true + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + false + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + false + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + + + ..\builds\$(Platform)\$(Configuration)\ + $(OutDir)objs\ + + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + Disabled + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBXPM_EXPORTS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + Level3 + EditAndContinue + + + $(OutDir)$(ProjectName)_debug.dll + ..\libxpm.def + true + false + + $(TargetDir)$(TargetName).lib + + + + + X64 + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + Disabled + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBXPM_EXPORTS;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + Level3 + ProgramDatabase + + + $(OutDir)$(ProjectName)_debug.dll + ..\libxpm.def + true + Windows + false + + MachineX64 + + + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBXPM_EXPORTS;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + + + ..\libxpm.def + true + Windows + true + true + false + + $(TargetDir)$(TargetName).lib + MachineX86 + + + + + X64 + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBXPM_EXPORTS;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + + + ..\libxpm.def + true + Windows + true + true + false + + MachineX64 + + + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + MaxSpeed + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + $(OutDir)libxpm_a.pdb + + + $(OutDir)libxpm_a.lib + + + + + X64 + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBXPM_EXPORTS;%(PreprocessorDefinitions) + MultiThreadedDLL + + Level3 + ProgramDatabase + $(OutDir)libxpm_a.pdb + + + $(OutDir)libxpm_a.lib + + + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + Disabled + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + ProgramDatabase + $(OutDir)libxpm_a_debug.pdb + + + $(OutDir)libxpm_a_debug.lib + + + + + X64 + + + /DFOR_MSW /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE %(AdditionalOptions) + Disabled + ..\..\include\X11;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + $(OutDir)libxpm_a_debug.pdb + + + $(OutDir)libxpm_a_debug.lib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/windows/vs17/libxpm.vcxproj.user b/windows/vs17/libxpm.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/windows/vs17/libxpm.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file