{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/7804","repository_url":"https://api.github.com/repos/astropy/astropy","labels_url":"https://api.github.com/repos/astropy/astropy/issues/7804/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/7804/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/7804/events","html_url":"https://github.com/astropy/astropy/issues/7804","id":357723003,"node_id":"MDU6SXNzdWUzNTc3MjMwMDM=","number":7804,"title":"WCS: missing error check for zero coordinates (ncoord)","user":{"login":"jamienoss","id":5013975,"node_id":"MDQ6VXNlcjUwMTM5NzU=","avatar_url":"https://avatars2.githubusercontent.com/u/5013975?v=4","gravatar_id":"","url":"https://api.github.com/users/jamienoss","html_url":"https://github.com/jamienoss","followers_url":"https://api.github.com/users/jamienoss/followers","following_url":"https://api.github.com/users/jamienoss/following{/other_user}","gists_url":"https://api.github.com/users/jamienoss/gists{/gist_id}","starred_url":"https://api.github.com/users/jamienoss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamienoss/subscriptions","organizations_url":"https://api.github.com/users/jamienoss/orgs","repos_url":"https://api.github.com/users/jamienoss/repos","events_url":"https://api.github.com/users/jamienoss/events{/privacy}","received_events_url":"https://api.github.com/users/jamienoss/received_events","type":"User","site_admin":false},"labels":[{"id":188323,"node_id":"MDU6TGFiZWwxODgzMjM=","url":"https://api.github.com/repos/astropy/astropy/labels/wcs","name":"wcs","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-09-06T15:59:53Z","updated_at":"2018-09-07T14:01:33Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"[src](https://github.com/astropy/astropy/blob/master/astropy/wcs/src/pipeline.c#L101-L108)\r\n```c\r\nint\r\npipeline_all_pixel2world(\r\n    pipeline_t* pipeline,\r\n    const unsigned int ncoord,\r\n    const unsigned int nelem,\r\n    const double* const pixcrd /* [ncoord][nelem] */,\r\n    double* world /* [ncoord][nelem] */) {\r\n\r\n...\r\n\r\nif (has_wcs) {\r\n    buffer = mem = malloc(\r\n        ncoord * nelem * sizeof(double) + /* imgcrd */\r\n        ncoord * sizeof(double) +         /* phi */\r\n        ncoord * sizeof(double) +         /* theta */\r\n        ncoord * nelem * sizeof(double) + /* tmp */\r\n        ncoord * nelem * sizeof(int)      /* stat */\r\n        );\r\n\r\n    if (buffer == NULL) {\r\n      status = wcserr_set(\r\n        PIP_ERRMSG(WCSERR_MEMORY), \"Memory allocation failed\");\r\n      goto exit;\r\n    }\r\n...\r\n```\r\n\r\nShouldn't there be a check for ``ncoord > 0`` before being used for allocation size? ``malloc`` can still accept a zero size so I'm not sure if this intentional or a bug? _c.f._ https://en.cppreference.com/w/c/memory/malloc\r\n\r\n> _\"If size is zero, the behavior is implementation defined (null pointer may be returned, or some\r\nnon-null pointer may be returned that may not be used to access storage, but has to be passed to free).\"_\r\n\r\nThis trips up in the subsequent call to ``wcsp2s`` [here](https://github.com/astropy/astropy/blob/master/astropy/wcs/src/pipeline.c#L144)  with the following error ([src](https://github.com/astropy/astropy/blob/master/cextern/wcslib/C/wcs.c#L2645-L2649)):\r\n```c\r\n...\r\n/* Sanity check. */\r\n  if (ncoord < 1 || (ncoord > 1 && nelem < wcs->naxis)) {\r\n    return wcserr_set(WCSERR_SET(WCSERR_BAD_CTYPE),\r\n      \"ncoord and/or nelem inconsistent with the wcsprm\");\r\n  }\r\n...\r\n```\r\n\r\nInspecting the values a this point for my example ``ncoord == 0``. (BTW: it's a good idea for errors to print values and boundaries.)\r\n\r\nThis is a similar error as reported in https://github.com/astropy/astropy/issues/4973 _\"Don't raise an error if passing zero coordinates to WCS\"_, excpet that it is in ``wcsp2s`` and not ``wcss2p``.\r\n\r\n```\r\nInconsistentAxisTypesError: ERROR 4 in wcsp2s() at line 2647 of file cextern/wcslib/C/wcs.c:\r\nncoord and/or nelem inconsistent with the wcsprm.\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/419448918","html_url":"https://github.com/astropy/astropy/issues/7804#issuecomment-419448918","issue_url":"https://api.github.com/repos/astropy/astropy/issues/7804","id":419448918,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTQ0ODkxOA==","user":{"login":"jamienoss","id":5013975,"node_id":"MDQ6VXNlcjUwMTM5NzU=","avatar_url":"https://avatars2.githubusercontent.com/u/5013975?v=4","gravatar_id":"","url":"https://api.github.com/users/jamienoss","html_url":"https://github.com/jamienoss","followers_url":"https://api.github.com/users/jamienoss/followers","following_url":"https://api.github.com/users/jamienoss/following{/other_user}","gists_url":"https://api.github.com/users/jamienoss/gists{/gist_id}","starred_url":"https://api.github.com/users/jamienoss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamienoss/subscriptions","organizations_url":"https://api.github.com/users/jamienoss/orgs","repos_url":"https://api.github.com/users/jamienoss/repos","events_url":"https://api.github.com/users/jamienoss/events{/privacy}","received_events_url":"https://api.github.com/users/jamienoss/received_events","type":"User","site_admin":false},"created_at":"2018-09-07T14:01:33Z","updated_at":"2018-09-07T14:01:33Z","author_association":"CONTRIBUTOR","body":"So the entry point is ``astropy.wcs. all_pix2world()`` from [here in Drizzle](https://github.com/spacetelescope/drizzle/blob/master/drizzle/calc_pixmap.py#L44).\r\n\r\n```\r\n~/dev/drizzle/build/lib.macosx-10.7-x86_64-3.6/drizzle/calc_pixmap.py in calc_pixmap(first_wcs, second_wcs)\r\n     42     idxmap = idxmap.reshape(first_naxis2 * first_naxis1, 2)\r\n     43 \r\n---> 44     worldmap = first_wcs.all_pix2world(idxmap, 1)\r\n     45 \r\n     46     if second_wcs.sip is None:\r\n\r\n//anaconda/lib/python3.6/site-packages/astropy/wcs/wcs.py in all_pix2world(self, *args, **kwargs)\r\n   1278     def all_pix2world(self, *args, **kwargs):\r\n   1279         return self._array_converter(\r\n-> 1280             self._all_pix2world, 'output', *args, **kwargs)\r\n   1281     all_pix2world.__doc__ = \"\"\"\r\n   1282         Transforms pixel coordinates to world coordinates.\r\n\r\n//anaconda/lib/python3.6/site-packages/astropy/wcs/wcs.py in _array_converter(self, func, sky, ra_dec_order, *args)\r\n   1254             if self.naxis == 1 and len(xy.shape) == 1:\r\n   1255                 return _return_list_of_arrays([xy], origin)\r\n-> 1256             return _return_single_array(xy, origin)\r\n   1257 \r\n   1258         elif len(args) == self.naxis + 1:\r\n\r\n//anaconda/lib/python3.6/site-packages/astropy/wcs/wcs.py in _return_single_array(xy, origin)\r\n   1238             if ra_dec_order and sky == 'input':\r\n   1239                 xy = self._denormalize_sky(xy)\r\n-> 1240             result = func(xy, origin)\r\n   1241             if ra_dec_order and sky == 'output':\r\n   1242                 result = self._normalize_sky(result)\r\n\r\nInconsistentAxisTypesError: ERROR 4 in wcsp2s() at line 2647 of file cextern/wcslib/C/wcs.c:\r\nncoord and/or nelem inconsistent with the wcsprm.\r\n```\r\n\r\n__However__ this is for astropy v3.0.4 and your fix (#7746) is currently only in master, as v2.0.9 hasn't been released yet.\r\n\r\nWhen using master (57de423b74cdf596754ab8ad09890d4a207a25e3) I no longer get this error, I do get another though but it's in drizzle and seems unrelated enough to not be covered in this issue.\r\n\r\nEither way, there are the above bugs in ``astropy/wcs/src/pipeline.c``.\r\n\r\n\r\n"}}
{"actor":{"display_login":"jamienoss"}}